diff --git a/src/challenge.ts b/src/challenge.ts index 63a7766..b1ce38c 100644 --- a/src/challenge.ts +++ b/src/challenge.ts @@ -9,6 +9,7 @@ // logger([1, 2, 3, "one", "two", "three"]); function logger(array: T[]): void { // write your code here... + array.forEach((element)=>console.log(element)) } // `toCelsius` function that: @@ -19,8 +20,8 @@ function logger(array: T[]): void { // toCelsius([32, 68, 100, 212]); // => [0, 20, 37.7778, 100] function toCelsius(temperatures: number[]): number[] { // write your code here... - - return []; // replace empty array with what you see is fit + + return temperatures.map((temp)=>(temp - 32) * (5/9)); // replace empty array with what you see is fit } // `hottestDays` function that: @@ -33,7 +34,7 @@ function toCelsius(temperatures: number[]): number[] { function hottestDays(temperatures: number[], threshold: number): number[] { // write your code here... - return []; // replace empty array with what you see is fit + return temperatures.filter(temps=>temps>=threshold); // replace empty array with what you see is fit } // `logHottestDays` function that: @@ -42,6 +43,7 @@ function hottestDays(temperatures: number[], threshold: number): number[] { // - Log temperatures that exceed the threshold to the console IN DEGREES CELSIUS (hint: you can combine all previous functions) function logHottestDays(temperatures: number[], threshold: number): void { // write your code here... + logger(toCelsius(hottestDays(temperatures,threshold))) } export { logger, toCelsius, hottestDays, logHottestDays }; diff --git a/src/filtering.ts b/src/filtering.ts index 49411d8..8c0d1a6 100644 --- a/src/filtering.ts +++ b/src/filtering.ts @@ -11,8 +11,8 @@ const numbers = [10, 13, 20, 25, 38, 35, 40]; // greaterThanTwentyFive(numbers); // => [38, 35, 40] function greaterThanTwentyFive(numbers: number[]): number[] { // write your code here... - - return []; // replace empty array with what you see is fit + let overtwentyfive = numbers.filter((num)=>num >= 25) + return overtwentyfive; // replace empty array with what you see is fit } // `divisibleByFive` function that: @@ -23,7 +23,7 @@ function greaterThanTwentyFive(numbers: number[]): number[] { function divisibleByFive(numbers: number[]): number[] { // write your code here... - return []; // replace empty array with what you see is fit + return numbers.filter((num)=>num%5===0); // replace empty array with what you see is fit } export { greaterThanTwentyFive, divisibleByFive }; diff --git a/src/mapping+filtering.ts b/src/mapping+filtering.ts index 269ad83..7eb8d72 100644 --- a/src/mapping+filtering.ts +++ b/src/mapping+filtering.ts @@ -11,8 +11,8 @@ const numbers = [10, 13, 20, 25, 38, 35, 40]; // filteredAndSquared(numbers); // => [400, 625, 1444, 1225, 1600] function filteredAndSquared(numbers: number[]): number[] { // write your code here... - - return []; // replace empty array with what you see is fit + + return numbers.filter((num)=>num >= 20).map((n)=>n*n); // replace empty array with what you see is fit } // `filteredAndTripled` function that: @@ -23,7 +23,7 @@ function filteredAndSquared(numbers: number[]): number[] { function filteredAndTripled(numbers: number[]): number[] { // write your code here... - return []; // replace empty array with what you see is fit + return numbers.filter((num)=>num%5 == 0).map((n)=>n*3);; // replace empty array with what you see is fit } export { filteredAndSquared, filteredAndTripled }; diff --git a/src/mapping.ts b/src/mapping.ts index 6f18eef..df08cf9 100644 --- a/src/mapping.ts +++ b/src/mapping.ts @@ -11,8 +11,8 @@ const numbers = [10, 13, 20, 25, 38, 35, 40]; // squaredNumbers(numbers); // => [100, 169, 400, 625, 1444, 1225, 1600] function squaredNumbers(numbers: number[]): number[] { // write your code here... - - return []; // replace empty array with what you see is fit + const squares = numbers.map((number)=>number*number) + return squares; // replace empty array with what you see is fit } // `doubledNumbers` function that: @@ -23,7 +23,7 @@ function squaredNumbers(numbers: number[]): number[] { function doubledNumbers(numbers: number[]): number[] { // write your code here... - return []; // replace empty array with what you see is fit + return numbers.map((number)=>number*2); // replace empty array with what you see is fit } export { squaredNumbers, doubledNumbers };