@josecarlosrz/array-helper
Advanced tools
Comparing version 1.0.0 to 1.0.1
65
index.js
module.exports = { | ||
unique: function(array) { | ||
forEach: async function(array, closure) { | ||
return array.filter(function(value, index, that) { | ||
return that.indexOf(value) === index; | ||
}); | ||
let thisArg; | ||
if (arguments.length > 2) { | ||
thisArg = arguments[2]; | ||
} | ||
for (let i = 0; i < array.length; i++) { | ||
await closure.call(thisArg, array[i], i, array); | ||
} | ||
}, | ||
forEach: async function(array) { | ||
find: async function(array, closure) { | ||
@@ -20,3 +26,7 @@ let thisArg; | ||
for (let i = 0; i < array.length; i++) { | ||
await closure.call(thisArg, array[i], i, array); | ||
if (await closure.call(thisArg, array[i], i, array)) { | ||
return array[i]; | ||
} | ||
} | ||
@@ -26,2 +36,22 @@ | ||
findIndex: async function(array, closure) { | ||
let thisArg; | ||
if (arguments.length > 2) { | ||
thisArg = arguments[2]; | ||
} | ||
for (let i = 0; i < array.length; i++) { | ||
if (await closure.call(thisArg, array[i], i, array)) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
}, | ||
map: async function(array, closure) { | ||
@@ -91,2 +121,22 @@ | ||
every: async function(array, closure) { | ||
let thisArg; | ||
if (arguments.length > 2) { | ||
thisArg = arguments[2]; | ||
} | ||
for (let i = 0; i < array.length; i++) { | ||
if (!await closure.call(thisArg, array[i], i, array)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}, | ||
reduce: async function(array, closure, value = null) { | ||
@@ -104,3 +154,3 @@ | ||
for (let i = array.length; i >= 0; i--) { | ||
for (let i = array.length - 1; i >= 0; i--) { | ||
value = await closure(value, array[i], i, array); | ||
@@ -114,3 +164,4 @@ } | ||
shuffle: require('./shuffle'), | ||
unique: require('./unique'), | ||
}; |
{ | ||
"name": "@josecarlosrz/array-helper", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Array helper to have async behavior and some util methods", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4836
5
116