From 7d7393f6fc67c9ce8d2b34200005a5dfe3ef1ecc Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Mon, 10 Mar 2025 13:19:39 +0300 Subject: [PATCH] Abdullah, Abdulrahman --- src/challenge.ts | 12 ++++++++---- src/filtering.ts | 6 +++++- src/mapping+filtering.ts | 8 ++++---- src/mapping.ts | 8 ++++---- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/challenge.ts b/src/challenge.ts index 63a7766..62fc057 100644 --- a/src/challenge.ts +++ b/src/challenge.ts @@ -9,6 +9,9 @@ // 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 +22,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 + const celsius = temperatures.map(f => {return ((f - 32) * (5/9))}) + return celsius; // replace empty array with what you see is fit } // `hottestDays` function that: @@ -32,8 +35,8 @@ function toCelsius(temperatures: number[]): number[] { // hottestDays([80, 90, 100, 110], 95); // => [100, 110] function hottestDays(temperatures: number[], threshold: number): number[] { // write your code here... - - return []; // replace empty array with what you see is fit + const hottest = temperatures.filter(temp => temp>=threshold) + return hottest; // replace empty array with what you see is fit } // `logHottestDays` function that: @@ -42,6 +45,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(temperatures.filter(temp => temp>=threshold))) } export { logger, toCelsius, hottestDays, logHottestDays }; diff --git a/src/filtering.ts b/src/filtering.ts index 49411d8..334c5ef 100644 --- a/src/filtering.ts +++ b/src/filtering.ts @@ -12,7 +12,9 @@ const numbers = [10, 13, 20, 25, 38, 35, 40]; function greaterThanTwentyFive(numbers: number[]): number[] { // write your code here... - return []; // replace empty array with what you see is fit + const filtered = numbers.filter(a => a>=25) + + return filtered; // replace empty array with what you see is fit } // `divisibleByFive` function that: @@ -22,7 +24,9 @@ function greaterThanTwentyFive(numbers: number[]): number[] { // divisibleByFive(numbers); // => [10, 20, 25, 35, 40] function divisibleByFive(numbers: number[]): number[] { // write your code here... + const filtered = numbers.filter(a => a % 5 === 0) + return filtered; return []; // replace empty array with what you see is fit } diff --git a/src/mapping+filtering.ts b/src/mapping+filtering.ts index 269ad83..7b01b5d 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 + const result = numbers.filter(n => n>=20).map(m => m**2) + return result; // replace empty array with what you see is fit } // `filteredAndTripled` function that: @@ -22,8 +22,8 @@ function filteredAndSquared(numbers: number[]): number[] { // filteredAndTripled(numbers); // => [30, 60, 75, 105, 120] function filteredAndTripled(numbers: number[]): number[] { // write your code here... - - return []; // replace empty array with what you see is fit + const result = numbers.filter(n => n%5===0).map(m => m*3) + return result; // replace empty array with what you see is fit } export { filteredAndSquared, filteredAndTripled }; diff --git a/src/mapping.ts b/src/mapping.ts index 6f18eef..8bb02af 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 mapped = numbers.map(n => n**2) + return mapped; // replace empty array with what you see is fit } // `doubledNumbers` function that: @@ -22,8 +22,8 @@ function squaredNumbers(numbers: number[]): number[] { // doubledNumbers(numbers); // => [20, 26, 40, 50, 76, 70, 80] function doubledNumbers(numbers: number[]): number[] { // write your code here... - - return []; // replace empty array with what you see is fit + const mapped = numbers.map(n => n*2) + return mapped; // replace empty array with what you see is fit } export { squaredNumbers, doubledNumbers };