@josecarlosrz/array-helper
Advanced tools
Comparing version 1.0.12 to 1.0.13
138
index.js
@@ -1,16 +0,16 @@ | ||
module.exports = { | ||
class ArrayHelper | ||
{ | ||
forEach: async function(array, closure) { | ||
static async forEach(array, closure) | ||
{ | ||
let thisArg; | ||
if (arguments.length > 2) { | ||
if (arguments.length > 2) | ||
thisArg = arguments[2]; | ||
} | ||
for (let i = 0; i < array.length; i++) { | ||
if (!(i in array)) { | ||
if (!(i in array)) | ||
continue; | ||
} | ||
@@ -21,11 +21,11 @@ await closure.call(thisArg, array[i], i, array); | ||
}, | ||
} | ||
map: async function(array, closure) { | ||
static async map(array, closure) | ||
{ | ||
let thisArg; | ||
if (arguments.length > 2) { | ||
if (arguments.length > 2) | ||
thisArg = arguments[2]; | ||
} | ||
@@ -36,5 +36,4 @@ const responses = []; | ||
if (!(i in array)) { | ||
if (!(i in array)) | ||
continue; | ||
} | ||
@@ -47,11 +46,11 @@ responses.push(await closure.call(thisArg, array[i], i, array)); | ||
}, | ||
} | ||
filter: async function(array, closure) { | ||
static async filter(array, closure) | ||
{ | ||
let thisArg; | ||
if (arguments.length > 2) { | ||
if (arguments.length > 2) | ||
thisArg = arguments[2]; | ||
} | ||
@@ -62,9 +61,7 @@ const newArray = []; | ||
if (!(i in array)) { | ||
if (!(i in array)) | ||
continue; | ||
} | ||
if (await closure.call(thisArg, array[i], i, array)) { | ||
if (await closure.call(thisArg, array[i], i, array)) | ||
newArray.push(array[i]); | ||
} | ||
@@ -75,21 +72,19 @@ } | ||
}, | ||
} | ||
some: async function(array, closure) { | ||
static async some(array, closure) | ||
{ | ||
let thisArg; | ||
if (arguments.length > 2) { | ||
if (arguments.length > 2) | ||
thisArg = arguments[2]; | ||
} | ||
for (let i = 0; i < array.length; i++) { | ||
if (!(i in array)) { | ||
if (!(i in array)) | ||
continue; | ||
} | ||
if (await closure.call(thisArg, array[i], i, array)) { | ||
if (await closure.call(thisArg, array[i], i, array)) | ||
return true; | ||
} | ||
@@ -100,21 +95,19 @@ } | ||
}, | ||
} | ||
every: async function(array, closure) { | ||
static async every(array, closure) | ||
{ | ||
let thisArg; | ||
if (arguments.length > 2) { | ||
if (arguments.length > 2) | ||
thisArg = arguments[2]; | ||
} | ||
for (let i = 0; i < array.length; i++) { | ||
if (!(i in array)) { | ||
if (!(i in array)) | ||
continue; | ||
} | ||
if (!await closure.call(thisArg, array[i], i, array)) { | ||
if (!await closure.call(thisArg, array[i], i, array)) | ||
return false; | ||
} | ||
@@ -125,35 +118,33 @@ } | ||
}, | ||
} | ||
find: async function(array, closure) { | ||
static async find(array, closure) | ||
{ | ||
let thisArg; | ||
if (arguments.length > 2) { | ||
if (arguments.length > 2) | ||
thisArg = arguments[2]; | ||
} | ||
for (let i = 0; i < array.length; i++) { | ||
if (await closure.call(thisArg, array[i], i, array)) { | ||
if (await closure.call(thisArg, array[i], i, array)) | ||
return array[i]; | ||
} | ||
} | ||
}, | ||
} | ||
findIndex: async function(array, closure) { | ||
static async findIndex(array, closure) | ||
{ | ||
let thisArg; | ||
if (arguments.length > 2) { | ||
if (arguments.length > 2) | ||
thisArg = arguments[2]; | ||
} | ||
for (let i = 0; i < array.length; i++) { | ||
if (await closure.call(thisArg, array[i], i, array)) { | ||
if (await closure.call(thisArg, array[i], i, array)) | ||
return i; | ||
} | ||
@@ -164,5 +155,6 @@ } | ||
}, | ||
} | ||
reduce: async function(array, closure) { | ||
static async reduce(array, closure) | ||
{ | ||
@@ -185,11 +177,11 @@ let value; | ||
for (let i = 0; i < array.length; i++) { | ||
for (let i = 0; i < array.length; i++) | ||
value = await closure(value, array[i], i, array); | ||
} | ||
return value; | ||
}, | ||
} | ||
reduceRight: async function(array, closure) { | ||
static async reduceRight(array, closure) | ||
{ | ||
@@ -212,29 +204,25 @@ let value; | ||
for (let i = array.length - 1; i >= 0; i--) { | ||
for (let i = array.length - 1; i >= 0; i--) | ||
value = await closure(value, array[i], i, array); | ||
} | ||
return value; | ||
}, | ||
} | ||
areEqual: function(a, b) { | ||
static areEqual(a, b) | ||
{ | ||
if (a === b) { | ||
if (a === b) | ||
return true; | ||
} | ||
if (a === null || b === null) { | ||
if (a === null || b === null) | ||
throw new TypeError('Arguments must be both arrays'); | ||
} | ||
if (a.length !== b.length) { | ||
if (a.length !== b.length) | ||
return false; | ||
} | ||
for (let i = 0; i < a.length; i++) { | ||
if (a[i] !== b[i]) { | ||
if (a[i] !== b[i]) | ||
return false; | ||
} | ||
@@ -245,14 +233,14 @@ } | ||
}, | ||
} | ||
unique: function(array) { | ||
static unique(array) | ||
{ | ||
return array.filter(function(value, index, that) { | ||
return that.indexOf(value) === index; | ||
}); | ||
return array.filter((value, index, that) => | ||
that.indexOf(value) === index); | ||
}, | ||
} | ||
shuffle: require('./shuffle'), | ||
}; | ||
} | ||
module.exports = ArrayHelper; |
{ | ||
"name": "@josecarlosrz/array-helper", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"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
7875
5
168