You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Write a function called doubleValues which accepts an array and returns a new array with all the values in the array passed to the function doubled
3
+
4
+
Examples:
5
+
doubleValues([1,2,3]) // [2,4,6]
6
+
doubleValues([5,1,2,3,10]) // [10,2,4,6,20]
7
+
8
+
*/
9
+
functiondoubleValues(arr){
10
+
constnewArr=[];
11
+
12
+
arr.forEach(function(char){
13
+
newArr.push(char+=char);
14
+
})
15
+
16
+
returnnewArr;
17
+
}
18
+
19
+
/*
20
+
Write a function called onlyEvenValues which accepts an array and returns a new array with only the even values in the array passed to the function
21
+
22
+
Examples:
23
+
onlyEvenValues([1,2,3]) // [2]
24
+
onlyEvenValues([5,1,2,3,10]) // [2,10]
25
+
26
+
*/
27
+
functiononlyEvenValues(arr){
28
+
constnewArr=[];
29
+
30
+
arr.forEach(function(char){
31
+
if(char%2===0){
32
+
newArr.push(char);
33
+
}
34
+
return;
35
+
})
36
+
37
+
returnnewArr;
38
+
}
39
+
40
+
/*
41
+
Write a function called showFirstAndLast which accepts an array of strings and returns a new array with only the first and last character of each string.
Write a function called addKeyAndValue which accepts an array of objects, a key, and a value and returns the array passed to the function with the new key and value added for each object
Write a function called vowelCount which accepts a string and returns an object with the keys as the vowel and the values as the number of times the vowel appears in the string. This function should be case insensitive so a lowercase letter and uppercase letter should count
86
+
87
+
Examples:
88
+
vowelCount('Elie') // {e:2,i:1};
89
+
vowelCount('Tim') // {i:1};
90
+
vowelCount('Matt') // {a:1})
91
+
vowelCount('hmmm') // {};
92
+
vowelCount('I Am awesome and so are you') // {i: 1, a: 4, e: 3, o: 3, u: 1};
93
+
*/
94
+
functionvowelCount(str){
95
+
constnewObj={};
96
+
constlowerCaseString=str.toLowerCase();
97
+
98
+
constisAVowel=function(ltr){
99
+
return"aeiou".indexOf(ltr)!==-1;
100
+
}
101
+
102
+
for(letcharoflowerCaseString){
103
+
if(isAVowel(char)){
104
+
if(newObj[char]){
105
+
newObj[char]++;
106
+
}
107
+
else{newObj[char]=1;}
108
+
}
109
+
}
110
+
returnnewObj;
111
+
}
112
+
113
+
/*
114
+
Write a function called doubleValuesWithMap which accepts an array and returns a new array with all the values in the array passed to the function doubled
115
+
116
+
Examples:
117
+
doubleValuesWithMap([1,2,3]) // [2,4,6]
118
+
doubleValuesWithMap([1,-2,-3]) // [2,-4,-6]
119
+
*/
120
+
121
+
functiondoubleValuesWithMap(arr){
122
+
returnarr.map(function(value){
123
+
return(value+value);
124
+
})
125
+
}
126
+
/*
127
+
Write a function called valTimesIndex which accepts an array and returns a new array with each value multiplied by the index it is currently at in the array.
128
+
129
+
Examples:
130
+
valTimesIndex([1,2,3]) // [0,2,6]
131
+
valTimesIndex([1,-2,-3]) // [0,-2,-6]
132
+
*/
133
+
134
+
functionvalTimesIndex(arr){
135
+
returnarr.map(function(value,i){
136
+
returnvalue*i;
137
+
})
138
+
}
139
+
140
+
/*
141
+
Write a function called extractKey which accepts an array of objects and some key and returns a new array with the value of that key in each object.
Write a function called extractFullName which accepts an array of objects and returns a new array with the value of the key with a name of "first" and the value of a key with the name of "last" in each object, concatenated together with a space.
Write a function called find which accepts an array and a value and returns the first element in the array that has the same value as the second parameter or undefined if the value is not found in the array.
183
+
184
+
Examples:
185
+
find([1,2,3,4,5], 3) // 3
186
+
find([1,2,3,4,5], 10) // undefined
187
+
*/
188
+
189
+
functionfind(arr,searchValue){
190
+
returnarr.filter(function(value){
191
+
returnvalue===searchValue;
192
+
})
193
+
[0];
194
+
}
195
+
196
+
/*
197
+
Write a function called findInObj which accepts an array of objects, a key, and some value to search for
0 commit comments