Parcourir la source

fixed recursive flatten call in array helper

mightyplow il y a 8 ans
Parent
commit
68b805c6c5
2 fichiers modifiés avec 12 ajouts et 10 suppressions
  1. 10 8
      lib/array.js
  2. 2 2
      package.json

+ 10 - 8
lib/array.js

@@ -1,13 +1,15 @@
 'use strict'
 
 module.exports = {
-    flatten: ar => ar.reduce((acc, item) => {
-        if (Array.isArray(item)) {
-            acc.push.apply(acc, flatten(item))
-        } else {
-            acc.push(item)
-        }
+    flatten: function flatten (ar) {
+        return ar.reduce((acc, item) => {
+            if (Array.isArray(item)) {
+                acc.push.apply(acc, flatten(item))
+            } else {
+                acc.push(item)
+            }
 
-        return acc
-    }, [])
+            return acc
+        }, [])
+    }
 }

+ 2 - 2
package.json

@@ -1,7 +1,7 @@
 {
   "name": "@mightyplow/jslib",
-  "version": "0.1.3",
-  "description": "js helpers library",
+  "version": "0.1.4",
+  "description": "js, helpers library",
   "main": "jslib.js",
   "dependencies": {
   },