Last active
June 28, 2017 06:02
-
-
Save jigewxy/e2618f059356b877bf957f391ec71008 to your computer and use it in GitHub Desktop.
JS Bin[controlled _.flatten function]// source https://jsbin.com/hinawagohe
This file contains 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
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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
make use of underscore flatten function to control the flatten level.