forked from rithmschool/udemy_course_exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreduce-exercises.js
More file actions
executable file
·38 lines (35 loc) · 850 Bytes
/
reduce-exercises.js
File metadata and controls
executable file
·38 lines (35 loc) · 850 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
29
30
31
32
33
34
35
36
37
38
function extractValue(arr, key){
return arr.reduce(function(acc,next){
acc.push(next[key]);
return acc;
},[]);
}
function vowelCount(str){
var vowels = "aeiou";
return str.toLowerCase().split('').reduce(function(acc,next){
if(vowels.indexOf(next) !== -1){
if(acc[next]){
acc[next]++;
} else {
acc[next] = 1;
}
}
return acc;
}, {});
}
function addKeyAndValue(arr, key, value){
return arr.reduce(function(acc,next,idx){
acc[idx][key] = value;
return acc;
},arr);
}
function partition(arr, callback){
return arr.reduce(function(acc,next){
if(callback(next)){
acc[0].push(next);
} else {
acc[1].push(next);
}
return acc;
}, [[],[]]);
}