Skip to content
Open

yay #15

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 34 additions & 20 deletions src/temperatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const temperatures = [
* filterHighTemperatures(temperatures); // => [25, 28, 30, 27, 29, 26, 28, 30, 27, 26, 25, 28, 29, 27, 26]
*/
function filterHighTemperatures(temps: number[]): number[] {
// Your code here

return []; // replace the empty array with what you see is fit
return temps.filter((temp) => {
return temp >= 25;
});
}

/**
Expand All @@ -28,9 +28,9 @@ function filterHighTemperatures(temps: number[]): number[] {
* filterLowTemperatures(temperatures); // => [19, 18, 19, 19]
*/
function filterLowTemperatures(temps: number[]): number[] {
// Your code here

return []; // replace the empty array with what you see is fit
return temps.filter((temp) => {
return temp < 20;
});
}

/**
Expand All @@ -42,9 +42,9 @@ function filterLowTemperatures(temps: number[]): number[] {
* convertCelsiusToFahrenheit([25, 30, 20]); // => [77, 86, 68]
*/
function convertCelsiusToFahrenheit(temps: number[]): number[] {
// Your code here

return []; // replace the empty array with what you see is fit
return temps.map((temp) => {
return temp * (9 / 5) + 32;
});
}

/**
Expand All @@ -59,10 +59,16 @@ function convertCelsiusToFahrenheit(temps: number[]): number[] {
*/
type TemperatureLabel = "Warm" | "Mild" | "Cool";

function labelTemperatures(temps: number[]): TemperatureLabel[] {
// Your code here

return []; // replace the empty array with what you see is fit
function labelTemperatures(temps: number[]) {
return temps.map((temp) => {
if (temp >= 25) {
return "Warm";
} else if (temp > 20 && temp < 24) {
return "Mild";
} else if (temp < 20) {
return "Cool";
}
});
}

/**
Expand All @@ -72,10 +78,14 @@ function labelTemperatures(temps: number[]): TemperatureLabel[] {
* Example:
* getMaxTemperature([25, 30, 20]); // => 30
*/
function getMaxTemperature(temps: number[]): number {
// Your code here

return -1; // replace -1 with what you see is fit
function getMaxTemperature(temps: number[]) {
let maxTemp = 0;
temps.forEach((temp) => {
if (temp > maxTemp) {
maxTemp = temp;
}
});
return maxTemp;
}

/**
Expand All @@ -86,9 +96,13 @@ function getMaxTemperature(temps: number[]): number {
* getMinTemperature([25, 30, 20]); // => 20
*/
function getMinTemperature(temps: number[]): number {
// Your code here

return -1; // replace -1 with what you see is fit
let minTemp = Infinity;
temps.forEach((temp) => {
if (temp < minTemp) {
minTemp = temp;
}
});
return minTemp;
}

export {
Expand Down