Преглед на файлове

fixed recursive flatten call in array helper

mightyplow преди 8 години
родител
ревизия
68b805c6c5
променени са 2 файла, в които са добавени 12 реда и са изтрити 10 реда
  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": {
   },