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
| // Fetched from server | |
| const nestedNumbers = [ | |
| [[0], [[[[[[[1, 2]]]]]]], [3]], | |
| [[[4], [[5]]], [[[6, 7, 8]]]], | |
| [9] | |
| ]; | |
| const incrementNestedNumbers = (arrayWithNums) => { | |
| for (let i = 0; i < arrayWithNums.length; i++) { | |
| if (Array.isArray(arrayWithNums[i])) { // if array |
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
| const nestedNumbers = [ | |
| [[0], [[[[[[[1, 2]]]]]]], [3]], | |
| [[[4], [[5]]], [[[6, 7, 8]]]], | |
| [9] | |
| ]; |
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
| out = []; | |
| for (let i = 0; i < 2; i++) { | |
| for (let j = 0; j < 2; j++) { | |
| out.push([ i, j ]); | |
| } | |
| } | |
| console.log(out); // -> [[ 0, 0 ], [ 0, 1 ], [ 1, 0 ], [ 1, 1 ]] |
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
| sum(); | |
| sum(1, 1)(); | |
| sum(1)(5)(12)(); | |
| sum(1)(132, 4)(); | |
| sum(1, 2, 3)(7, 8, 9)(5)(); | |
| sum(1, 1)(4)(6, 13, 7)(2)(3)(2)(2, 1)(); |
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
| const comments = [ | |
| { | |
| text: 'comment 1', | |
| comments: [ | |
| { | |
| text: 'comment 2', | |
| comments: [], | |
| }, | |
| ], | |
| }, |
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
| const traverseHtmlElement = (rootElement, _level = 0) => { | |
| // Get all element's children stringified if any | |
| let rootChildren = ''; | |
| if (rootElement.childElementCount) { | |
| rootChildren = traverseHtmlElement(rootElement.firstElementChild, _level + 1); | |
| } | |
| // Get all element's siblings stringified if any | |
| let rootSiblings = ''; | |
| const nextSibling = rootElement.nextElementSibling; |
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
| const bodyChildren = [...document.body.children]; | |
| for (let i = 0; i < bodyChildren.length; i++) { | |
| // So... how do we get children of each body child? | |
| analyseElement(bodyChildren[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
| const flatToBase = array => array.reduce( | |
| (accumulator, value) => accumulator.concat( | |
| Array.isArray(value) ? flatToBase(value) : value | |
| ), | |
| [], | |
| ); | |
| flatToBase([[[[[[[ 42 ]]]], 36]]]); // -> [ 42, 36 ] |
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
| nestedArrays.flat(Infinity); |
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
| const mirrorNumbersUpTo = (num) => { | |
| console.log(num); | |
| if (num > 0) { | |
| mirrorNumbersUpTo(num - 1); | |
| console.log(num); | |
| } | |
| }; | |
| mirrorNumbersUpTo(5); // ➡️ logs 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5 |
NewerOlder