Last active
January 29, 2020 11:15
-
-
Save mariuszklinger/330bbf5d7cd4fccc0f1b127c684c4a74 to your computer and use it in GitHub Desktop.
Revisions
-
mariuszklinger revised this gist
Jan 29, 2020 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,13 +6,14 @@ function flat(arr) { while (stack.length) { const current = stack.shift(); const isCurrentArray = Array.isArray(current); if (isCurrentArray) { stack.unshift(...current); continue; } result.push(current); } return result; -
mariuszklinger revised this gist
Jan 28, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ const example1 = [[1, 1, 1, [1.4, 1.6]], 666, [2, 3, [[4], [5, 6]]]]; function flat(arr) { const stack = arr; -
mariuszklinger revised this gist
Jan 28, 2020 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,11 @@ const example1 = [[1,1,1,[1.4, 1.6]], 666, [2, 3, [[4], [5, 6]]]]; function flat(arr) { const stack = arr; const result = []; while (stack.length) { const current = stack.shift(); if (Array.isArray(current)) { stack.unshift(...current); -
mariuszklinger revised this gist
Jan 28, 2020 . No changes.There are no files selected for viewing
-
mariuszklinger revised this gist
Jan 28, 2020 . No changes.There are no files selected for viewing
-
mariuszklinger created this gist
Jan 28, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ const example1 = [[1,1,1,[1.4, 1.6]], 666, [2, 3, [[4], [5, 6]]]]; function flat(arr) { const stack = arr; const result = []; while (stack.length) { const current = stack.shift(); if (Array.isArray(current)) { stack.unshift(...current); } else { result.push(current); } } return result; } console.assert(`${flat(example1)}`, '1,1,1,1.4,1.6,666,2,3,4,5,6');