Skip to content
Open

done #18

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
24 changes: 14 additions & 10 deletions src/temperatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ const temperatures = [
function filterHighTemperatures(temps: number[]): number[] {
// Your code here

return []; // replace the empty array with what you see is fit
return temps.filter((temperature) => temperature >= 25); // replace the empty array with what you see is fit
}
console.log(filterHighTemperatures(temperatures));

/**
* `filterLowTemperatures` function:
Expand All @@ -30,8 +31,9 @@ function filterHighTemperatures(temps: number[]): number[] {
function filterLowTemperatures(temps: number[]): number[] {
// Your code here

return []; // replace the empty array with what you see is fit
return temps.filter((temperature) => temperature < 20); // replace the empty array with what you see is fit
}
console.log(filterHighTemperatures(temperatures));

/**
* `convertCelsiusToFahrenheit` function:
Expand All @@ -42,9 +44,7 @@ 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((celsius) => (celsius * 9) / 5 + 32);
}

/**
Expand All @@ -57,14 +57,18 @@ function convertCelsiusToFahrenheit(temps: number[]): number[] {
* Example:
* labelTemperatures([25, 22, 18]); // => ["Warm", "Mild", "Cool"]
*/

type TemperatureLabel = "Warm" | "Mild" | "Cool";

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

return []; // replace the empty array with what you see is fit
return temps.map((temperature) => {
if (temperature >= 25) return "Warm";
if (temperature >= 20) return "Mild";
return "Cool";
});
}

console.log(labelTemperatures(temperatures));
/**
* `getMaxTemperature` function:
* - Accepts a "temps" parameter of type "number[]".
Expand All @@ -75,7 +79,7 @@ function labelTemperatures(temps: number[]): TemperatureLabel[] {
function getMaxTemperature(temps: number[]): number {
// Your code here

return -1; // replace -1 with what you see is fit
return Math.max(...temps); // replace -1 with what you see is fit
}

/**
Expand All @@ -88,7 +92,7 @@ function getMaxTemperature(temps: number[]): number {
function getMinTemperature(temps: number[]): number {
// Your code here

return -1; // replace -1 with what you see is fit
return temps.reduce((min, temp) => (temp < min ? temp : min), temps[0]); // replace -1 with what you see is fit
}

export {
Expand Down