Skip to content

Instantly share code, notes, and snippets.

@benravago
Created January 23, 2019 22:08
Show Gist options
  • Select an option

  • Save benravago/b7ef110adbddada617a02169093fdefa to your computer and use it in GitHub Desktop.

Select an option

Save benravago/b7ef110adbddada617a02169093fdefa to your computer and use it in GitHub Desktop.
flatten an arbitrary integer array
function flatten(a) {
if (!Array.isArray(a)) {
throw("Not an array: "+a);
}
let b = new Array();
append(a);
return b;
function append(x) {
if (Array.isArray(x)) {
for (let i = 0; i < x.length; i++) {
append(x[i]);
}
} else {
b.push(x);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment