This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = [1,2,[3,4,[5,6,[7,8]]]] | |
| b = [9, 10] | |
| function flatten() { | |
| let new_arr = [] | |
| for(let i=0; i < arguments.length ; i++){ | |
| new_arr = new_arr.concat(arguments[i]) | |
| } | |
| return new_arr.reduce(function (flattened_arr, j) { | |
| return j instanceof Array ? flattened_arr.concat(flatten(j)) : flattened_arr.concat(j); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function flatten(a) { | |
| if (a instanceof Array) { | |
| return a.reduce((flat, i) => { | |
| if (i instanceof Array) { | |
| return flat.concat(flatten(i)); | |
| } | |
| return flat.concat(i); | |
| }, []); | |
| } | |
| return a; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var a = [1,2,3,4,[5,6,7]] | |
| var b = [8,9,10] | |
| function flatten() { | |
| var new_arr = [] | |
| for(i=0; i < arguments.length - 1 ; i++){ | |
| for(j=0; j < arguments[i].length; j++){ | |
| if(arguments[i][j] instanceof Array){ | |
| new_arr = new_arr.push(flatten(arguments[i][j])) | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let a = [1,2,3,4,5] | |
| let b = [1,2,3,4,5] | |
| function flatten() { | |
| var new_arr = [] | |
| for(i=0; i < arguments.length; i++){ | |
| new_arr = new_arr.concat(arguments[i]) | |
| } | |
| return new_arr | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function add(arg1){ | |
| return function(arg2) { | |
| return arg1 + arg2 | |
| } | |
| } | |
| add(2)(3) | |
| // 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function add(arg1){ | |
| // intermediate variable | |
| let first_execution = arg1 | |
| return function(arg2) { | |
| return first_execution + arg2 | |
| } | |
| } | |
| add(2)(3) | |
| // 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add(2, 5); // 7 | |
| add(2)(5); // 7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for(i=0; i <= 100; i++){ | |
| console.log((i % 3 ? '' : 'fizz') + (i % 5 ? '' : 'buzz') || i) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for(i = 0; i <= 100; i++){ | |
| let output = '' | |
| if(i % 3 === 0){ | |
| output+='fizz' | |
| } | |
| if(i % 5 === 0){ | |
| output+='buzz' | |
| } | |
| if(output === ''){ | |
| output+=i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for(i=0; i <= 100; i++){ | |
| if (i % 3 === 0 && i % 5 === 0){ | |
| console.log('fizzbuzz') | |
| } else if (i % 3 === 0){ | |
| console.log('fizz') | |
| } else if (i % 5 === 0){ | |
| console.log('buzz') | |
| } else { | |
| console.log(i) | |
| } |