2 changed files with 0 additions and 60 deletions
@ -1,59 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
/* Array utilities. */ |
|||
let arrays = { |
|||
range: function(start, stop) { |
|||
let length = stop - start, |
|||
result = new Array(length); |
|||
|
|||
for (let i = 0, j = start; i < length; i++, j++) { |
|||
result[i] = j; |
|||
} |
|||
|
|||
return result; |
|||
}, |
|||
|
|||
find: function(array, valueOrPredicate) { |
|||
let length = array.length; |
|||
|
|||
if (typeof valueOrPredicate === "function") { |
|||
for (let i = 0; i < length; i++) { |
|||
if (valueOrPredicate(array[i])) { |
|||
return array[i]; |
|||
} |
|||
} |
|||
} else { |
|||
for (let i = 0; i < length; i++) { |
|||
if (array[i] === valueOrPredicate) { |
|||
return array[i]; |
|||
} |
|||
} |
|||
} |
|||
}, |
|||
|
|||
indexOf: function(array, valueOrPredicate) { |
|||
let length = array.length; |
|||
|
|||
if (typeof valueOrPredicate === "function") { |
|||
for (let i = 0; i < length; i++) { |
|||
if (valueOrPredicate(array[i])) { |
|||
return i; |
|||
} |
|||
} |
|||
} else { |
|||
for (let i = 0; i < length; i++) { |
|||
if (array[i] === valueOrPredicate) { |
|||
return i; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return -1; |
|||
}, |
|||
|
|||
contains: function(array, valueOrPredicate) { |
|||
return arrays.indexOf(array, valueOrPredicate) !== -1; |
|||
} |
|||
}; |
|||
|
|||
module.exports = arrays; |
Loading…
Reference in new issue