Skip to content

Commit 28d4657

Browse files
committed
Added and completed flatted for Underbar. Implemented it recursively.
1 parent d6f7058 commit 28d4657

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/underbar.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,19 @@ var _ = {};
654654
//
655655
// Hint: Use Array.isArray to check if something is an array
656656
_.flatten = function(nestedArray, result) {
657+
var result=[];
658+
659+
var extractArray = function(arrays, result) {
660+
_.each(arrays, function(arr) {
661+
if (Array.isArray(arr)) {
662+
extractArray(arr, result);
663+
} else {
664+
result.push(arr);
665+
}
666+
});
667+
};
668+
extractArray(nestedArray, result);
669+
return result;
657670
};
658671

659672
// Takes an arbitrary number of arrays and produces an array that contains

0 commit comments

Comments
 (0)