Skip to content

Instantly share code, notes, and snippets.

@oliverjam
Created June 10, 2017 14:56
Show Gist options
  • Select an option

  • Save oliverjam/d9ef81fbf7b65665b3072777c437af3b to your computer and use it in GitHub Desktop.

Select an option

Save oliverjam/d9ef81fbf7b65665b3072777c437af3b to your computer and use it in GitHub Desktop.
Recursive nested array count created by oliverjam - https://repl.it/If1v/0
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