Skip to content

Commit ba6bfbe

Browse files
committed
updated
1 parent cfb8004 commit ba6bfbe

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

JavaScript Problem Solving/veryEasy.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,36 @@
1313
// reference.
1414
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
1515

16+
17+
/*
18+
Things learned:
19+
1. Make sure you really understand .map
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+
1646
/*
1747
Is the Last Character an N?
1848
Create a function that takes a string (a random name). If the last character of the name is an "n", return true, otherwise return false.
@@ -127,7 +157,11 @@ ES6: Destructuring Arrays III
127157
You can assign variables from arrays with destructuring like this:
128158
const arr = ["eyes", "nose", "lips", "ears"]
129159
let [eyes, nose, lips, ears] = arr
160+
NOTE: I used ",," to skip over items in the array being destrcutured: https://hacks.mozilla.org/2015/05/es6-in-depth-destructuring/
161+
NOTE: Each comma means equals one index (i.e. ",," equals index[1] and ",,," equals index[2])
130162
*/
163+
const arr = ["eyes", "nose", "lips", "ears"]
164+
var [,,lips] = arr // skips over items
131165

132166

133167

@@ -142,6 +176,7 @@ function stackBoxes(n) {
142176
}
143177

144178

179+
145180
/*
146181
Array of Word Lengths
147182
Create a function that takes an array of words and transforms it into an array of each word's length.
@@ -150,4 +185,28 @@ function wordLengths(arr) {
150185
return arr.map(function(word) {
151186
return word.length;
152187
});
188+
}
189+
190+
191+
192+
/*
193+
Count the Syllables
194+
Create a function that returns the number of syllables in a simple string. The string is made up of short repeated words like "Lalalalalalala" (which would have 7 syllables).
195+
countSyllables("Hehehehehehe") ➞ 6
196+
*/
197+
function countSyllables(str) {
198+
return str.length/2;
199+
}
200+
201+
202+
/*
203+
Add the Index
204+
Given an array of numbers, create a function which returns the same array but with each element's index in the array added to itself. This means you add 0 to the number at index 0, add 1 to the number at index 1, etc...
205+
addIndexes([0, 0, 0, 0, 0]) ➞ [0, 1, 2, 3, 4]
206+
addIndexes([1, 2, 3, 4, 5]) ➞ [1, 3, 5, 7, 9]
207+
*/
208+
function addIndexes(arr) {
209+
return arr.map(function(currentVal, indexVal) {
210+
return currentVal + indexVal;
211+
});
153212
}

0 commit comments

Comments
 (0)