-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
123 lines (55 loc) · 3.25 KB
/
index.js
File metadata and controls
123 lines (55 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Practice Test: Higher Order Functions, Callbacks & Recursion
// Problem 1
// Write a function `capitalizeWords` that takes an array of strings and
// returns a new array with each word capitalized. Use `map()`.
// Problem 2
// Create a function `countVowels` that uses recursion to count how
// many vowels are in a string.
// Problem 3
// Implement a function `delayedGreeting` that takes a name and a callback
// function, then executes the callback after a 1-second delay with the greeting
// "Hello, [name]!".
// Problem 4
// Write a function `filterByLength` that takes an array of strings and a number,
// then returns a new array with only strings longer than the given number.
// Use `filter()`.
// Problem 5
// Create a recursive function `reverseString` that reverses any string passed to it.
// Problem 6
// Implement a function `processNumbers` that takes an array of numbers and two callbacks.
// It should apply the first callback to even numbers and the second to odd numbers, returning
// a new array.
// Problem 7
// Write a function `sumSquares` that uses `reduce()` to calculate the sum of squares of all
// numbers in an array.
// Problem 8
// Create a function `countdown` that uses recursion to log numbers from a given number down to 0.
// Problem 9
// Implement a higher-order function `applyTwice` that takes a function and a value, and applies the
// function to the value twice.
// Problem 10
// Write a function `findFirstPositive` that uses `find()` to locate the first positive number in an array.
// Problem 11
// Create a recursive function `flattenArray` that takes a nested array and returns a flattened version
// (one level deep).
// Problem 12
// Implement a function `asyncMultiply` that takes two numbers and a callback, then uses `setTimeout` to
// call the callback with the product after 500ms.
// Problem 13
// Write a function `allTruthy` that uses `every()` to check if all elements in an array are truthy.
// Problem 14
// Create a function `alternateCaps` that takes a string and a callback, then applies the callback to alternate
// characters (odd-indexed characters uppercase, even-indexed lowercase).
// Problem 15
// Write a recursive function `sumDigits` that takes a positive integer and returns the sum of its digits.
// Problem 16
// Create a recursive function `countOccurrences` that takes an array and a target value, returning how many times the target appears in the array.
// Problem 17
// Implement a recursive function `range` that takes two numbers (a, b) and returns an array of all integers between them, inclusive.
// Problem 18
// Write a recursive function `deepCount` that returns the number of elements in a nested array (counting all elements at all levels).
// Problem 19
// Create a recursive function `binarySearch` that implements the binary search algorithm on a sorted array, returning the index of the target element or -1 if not found.
// Problem 20 (Advanced, please dont stress this is just for us to get comfortable with not knowing something)
// Implement a memoized recursive Fibonacci function that uses tail call optimization principles. The function
// should efficiently calculate Fibonacci numbers without redundant calculations or stack overflow.