Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// logger<number | string>([1, 2, 3, "one", "two", "three"]);
function logger<T>(array: T[]): void {
// write your code here...
array.forEach((element) => console.log(element));
}

// `toCelsius` function that:
Expand All @@ -19,8 +20,7 @@ function logger<T>(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((temps) => (temps - 32) * (5 / 9)); // replace empty array with what you see is fit
}

// `hottestDays` function that:
Expand All @@ -32,8 +32,7 @@ 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
return temperatures.filter((temps) => temps > threshold); // replace empty array with what you see is fit
}

// `logHottestDays` function that:
Expand All @@ -42,6 +41,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 };
6 changes: 2 additions & 4 deletions src/filtering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ 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
return numbers.filter((num) => num >= 25); // replace empty array with what you see is fit
}

// `divisibleByFive` function that:
Expand All @@ -22,8 +21,7 @@ function greaterThanTwentyFive(numbers: number[]): number[] {
// divisibleByFive(numbers); // => [10, 20, 25, 35, 40]
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 };
6 changes: 2 additions & 4 deletions src/mapping+filtering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ 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((num) => Math.pow(num, 2)); // replace empty array with what you see is fit
}

// `filteredAndTripled` function that:
Expand All @@ -22,8 +21,7 @@ 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
return numbers.filter((num) => num % 5 === 0).map((num) => num * 3); // replace empty array with what you see is fit
}

export { filteredAndSquared, filteredAndTripled };
6 changes: 2 additions & 4 deletions src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ 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
return numbers.map((num) => Math.pow(num, 2)); // replace empty array with what you see is fit
}

// `doubledNumbers` function that:
Expand All @@ -22,8 +21,7 @@ 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
return numbers.map((num) => num * 2); // replace empty array with what you see is fit
}

export { squaredNumbers, doubledNumbers };