diff --git a/src/temperatures.ts b/src/temperatures.ts index bc788d5..b2addd5 100644 --- a/src/temperatures.ts +++ b/src/temperatures.ts @@ -16,8 +16,7 @@ const temperatures = [ */ function filterHighTemperatures(temps: number[]): number[] { // Your code here - - return []; // replace the empty array with what you see is fit + return temps.filter((temprature) => temprature >= 25); // replace the empty array with what you see is fit } /** @@ -29,8 +28,7 @@ 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((temprature) => temprature < 20); // replace the empty array with what you see is fit } /** @@ -43,8 +41,7 @@ function filterLowTemperatures(temps: number[]): number[] { */ function convertCelsiusToFahrenheit(temps: number[]): number[] { // Your code here - - return []; // replace the empty array with what you see is fit + return temps.map((temperature) => temperature * 1.8 + 32); // replace the empty array with what you see is fit } /** @@ -62,7 +59,25 @@ type TemperatureLabel = "Warm" | "Mild" | "Cool"; function labelTemperatures(temps: number[]): TemperatureLabel[] { // Your code here - return []; // replace the empty array with what you see is fit + // 1st solution + // return temps.map((temperature) => { + // if (temperature >= 25) { + // return "Warm"; + // } else if (temperature >= 20 && temperature <= 24) { + // return "Mild"; + // } else { + // return "Cool"; + // } + // }); + + // 2nd solution + return temps.map((temperature) => + temperature >= 25 + ? "Warm" + : temperature >= 20 && temperature <= 24 + ? "Mild" + : "Cool" + ); // replace the empty array with what you see is fit } /** @@ -74,8 +89,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 } /** @@ -87,8 +101,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 Math.min(...temps); // replace -1 with what you see is fit } export {