Skip to content

Instantly share code, notes, and snippets.

@jigewxy
Last active June 28, 2017 06:02
Show Gist options
  • Save jigewxy/e2618f059356b877bf957f391ec71008 to your computer and use it in GitHub Desktop.
Save jigewxy/e2618f059356b877bf957f391ec71008 to your computer and use it in GitHub Desktop.
JS Bin[controlled _.flatten function]// source https://jsbin.com/hinawagohe
var arr =[1, [2,[3, [4, [5, [6]]]]]];
function flattenCtrl(list, level){
do {
list=_.flatten(list, true);
level--;
} while(level>0);
return list;
}
console.log(flattenCtrl(arr, 10));
@jigewxy
Copy link
Author

jigewxy commented Jun 28, 2017

make use of underscore flatten function to control the flatten level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment