-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwarmup.js
More file actions
28 lines (24 loc) · 994 Bytes
/
warmup.js
File metadata and controls
28 lines (24 loc) · 994 Bytes
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
/*
===========================================================================
WARMUP TO BE DONE AFTER EXERCISES
===========================================================================
*/
// Exercises
// Discuss the purpose of reduce with your partner until both of you are
// confident that you could explain its purpose to the class. Try to describe
// what reduce does, not how it does it.
// Rewrite the sumCubes function below using reduce instead of each:
function sumCubes(numbers) {
var total = 0;
each(numbers, function(number) {
total = total + Math.pow(number, 3);
});
return total;
}
// Write a function called smallestWords that accepts two parameters, string
// and threshold (number), and returns an array containing all the words
// smaller than threshold. You should use reduce to complete this function.
function smallestWords(string, threshold) {
// YOUR CODE HERE
}
smallestWords("the quick brown fox", 4); // => ["the", "fox"]