@amphibian/iterate-down-array
v1.0.2
Published
while loop abstraction for looping through indices from Array.length to 0
Downloads
5
Readme
iterate-down-array
while loop abstraction for looping through indices from Array.length to 0
npm install @amphibian/iterate-down-array
var iterateDownArray = require('@amphibian/iterate-down');
var array = ['zero', 'one', 'two'];
// Iterate from the last index to the first
iterateDownArray(array, function (index, i) {
console.log(index, i); // two 2, one 1, zero 0
});
// Iterate from the last index to the first, but stop if the key is `one`
var question = iterateDownArray(array, function (index, i, end) {
console.log(index, i); // two 2, one 1
if (index === 'one') {
end('hola que hora es');
}
});
console.log(question); // > hola que hora es