Created
June 10, 2017 14:56
-
-
Save oliverjam/d9ef81fbf7b65665b3072777c437af3b to your computer and use it in GitHub Desktop.
Recursive nested array count created by oliverjam - https://repl.it/If1v/0
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 deepCount(arr) { | |
| return arr.reduce((acc, item) => { | |
| acc += 1; | |
| if (Array.isArray(item)) acc += deepCount(item); | |
| return acc; | |
| }, 0); | |
| } | |
| const a = [1, [2, 3, [4, 5, 6]]]; | |
| deepCount(a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment