@josecarlosrz/array-helper
Advanced tools
Comparing version 1.0.3 to 1.0.4
110
index.js
@@ -12,3 +12,9 @@ module.exports = { | ||
for (let i = 0; i < array.length; i++) { | ||
if (!(i in array)) { | ||
continue; | ||
} | ||
await closure.call(thisArg, array[i], i, array); | ||
} | ||
@@ -18,3 +24,3 @@ | ||
find: async function(array, closure) { | ||
map: async function(array, closure) { | ||
@@ -27,13 +33,19 @@ let thisArg; | ||
const responses = []; | ||
for (let i = 0; i < array.length; i++) { | ||
if (await closure.call(thisArg, array[i], i, array)) { | ||
return array[i]; | ||
if (!(i in array)) { | ||
continue; | ||
} | ||
responses.push(await closure.call(thisArg, array[i], i, array)); | ||
} | ||
return responses; | ||
}, | ||
findIndex: async function(array, closure) { | ||
filter: async function(array, closure) { | ||
@@ -46,6 +58,12 @@ let thisArg; | ||
const newArray = []; | ||
for (let i = 0; i < array.length; i++) { | ||
if (!(i in array)) { | ||
continue; | ||
} | ||
if (await closure.call(thisArg, array[i], i, array)) { | ||
return i; | ||
newArray.push(array[i]); | ||
} | ||
@@ -55,7 +73,7 @@ | ||
return -1; | ||
return newArray; | ||
}, | ||
map: async function(array, closure) { | ||
some: async function(array, closure) { | ||
@@ -68,13 +86,19 @@ let thisArg; | ||
const responses = []; | ||
for (let i = 0; i < array.length; i++) { | ||
responses.push(await closure.call(thisArg, array[i], i, array)); | ||
if (!(i in array)) { | ||
continue; | ||
} | ||
if (await closure.call(thisArg, array[i], i, array)) { | ||
return true; | ||
} | ||
} | ||
return responses; | ||
return false; | ||
}, | ||
filter: async function(array, closure) { | ||
every: async function(array, closure) { | ||
@@ -87,17 +111,19 @@ let thisArg; | ||
const newArray = []; | ||
for (let i = 0; i < array.length; i++) { | ||
if (await closure.call(thisArg, array[i], i, array)) { | ||
newArray.push(array[i]); | ||
if (!(i in array)) { | ||
continue; | ||
} | ||
if (!await closure.call(thisArg, array[i], i, array)) { | ||
return false; | ||
} | ||
} | ||
return newArray; | ||
return true; | ||
}, | ||
some: async function(array, closure) { | ||
find: async function(array, closure) { | ||
@@ -113,3 +139,3 @@ let thisArg; | ||
if (await closure.call(thisArg, array[i], i, array)) { | ||
return true; | ||
return array[i]; | ||
} | ||
@@ -119,7 +145,5 @@ | ||
return false; | ||
}, | ||
every: async function(array, closure) { | ||
findIndex: async function(array, closure) { | ||
@@ -134,4 +158,4 @@ let thisArg; | ||
if (!await closure.call(thisArg, array[i], i, array)) { | ||
return false; | ||
if (await closure.call(thisArg, array[i], i, array)) { | ||
return i; | ||
} | ||
@@ -141,8 +165,24 @@ | ||
return true; | ||
return -1; | ||
}, | ||
reduce: async function(array, closure, value = null) { | ||
reduce: async function(array, closure) { | ||
let value; | ||
if (arguments.length > 2) { | ||
value = arguments[2]; | ||
} else if (array.length > 0) { | ||
value = array[0]; | ||
} else { | ||
throw new TypeError('Reduce of empty array with no initial value'); | ||
} | ||
for (let i = 0; i < array.length; i++) { | ||
@@ -156,4 +196,20 @@ value = await closure(value, array[i], i, array); | ||
reduceRight: async function(array, closure, value = null) { | ||
reduceRight: async function(array, closure) { | ||
let value; | ||
if (arguments.length > 2) { | ||
value = arguments[2]; | ||
} else if (array.length > 0) { | ||
value = array[0]; | ||
} else { | ||
throw new TypeError('Reduce of empty array with no initial value'); | ||
} | ||
for (let i = array.length - 1; i >= 0; i--) { | ||
@@ -160,0 +216,0 @@ value = await closure(value, array[i], i, array); |
{ | ||
"name": "@josecarlosrz/array-helper", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"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
5988
145
5