Permalink
Browse files

add flatten

  • Loading branch information...
1 parent 16b5868 commit 4e23600d27e184680cc74402759e63b39266bac8 @dominictarr committed Sep 26, 2011
Showing with 13 additions and 1 deletion.
  1. +13 −1 arrays.js
View
@@ -43,6 +43,17 @@ function head(array){
return empty(array) ? null : array[0]
}
+function flatten (nested) {
+ var a = []
+ function denest (item) {
+ if(Array.isArray(item))
+ item.forEach(denest)
+ else a.push(item)
+ }
+ denest(nested)
+ return a
+}
+
module.exports = {
throwIfEmpty: throwIfEmpty,
init: init,
@@ -53,5 +64,6 @@ module.exports = {
strictTail: strictTail,
strictLast: strictLast,
strictHead: strictHead,
- empty: empty
+ empty: empty,
+ flatten: flatten
}

0 comments on commit 4e23600

Please sign in to comment.