File tree 1 file changed +8
-2
lines changed
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -36,16 +36,22 @@ const cacheFunction = cb => {
36
36
37
37
/* ======================== Recursion Practice ============================ */
38
38
const reverseStr = str => {
39
- return str . split ( '' ) . reverse ( ) . join ( '' ) ;
39
+ var first = str [ 0 ] ;
40
+ var last = str [ str . length - 1 ] ;
41
+ var str1 = reverseStr ( str . substring ( 1 , str . length - 1 ) ) ;
42
+ return last + str1 + first ;
40
43
} ;
44
+ // based on https://stackoverflow.com/questions/4859208/recursive-string-reversal-function-in-javascript
41
45
42
46
const checkMatchingLeaves = obj => {
43
47
// return true if every property on `obj` is the same
44
48
// otherwise return false
45
49
} ;
46
50
47
51
const flatten = elements => {
48
- each ( )
52
+ each ( elements , element => { // call each function to iterate over the array
53
+ elements = flatten ( [ ] . concat ( [ ] , ...elements ) ) ; // flatten by breaking out nested arrays as we recursively call flatten function
54
+ } ) ;
49
55
} ;
50
56
51
57
module . exports = {
You can’t perform that action at this time.
0 commit comments