Array.prototype.find does not skip holes

Fixes #103
This commit is contained in:
André Bargull 2015-03-23 19:15:16 +01:00
parent ceeefa3196
commit 73a8a7dcf9
1 changed files with 18 additions and 8 deletions

View File

@ -3,28 +3,38 @@
/*---
description: >
Elements removed from array after find has been called should not
be visited
Elements removed from array after find has been called should be
visited
---*/
var elementsVisited;
elementsVisited = 0;
[1, 'string', 2].find(function (v, i, arr) {
elementsVisited++;
var stringIndex = arr.indexOf('string');
if (stringIndex !== -1) delete arr[stringIndex];
if (v === 'string') {
$ERROR('#1: \'string\' should not exist, it has been deleted');
}
if (v === undefined) {
$ERROR('#2: deleted element should not be visited');
}
});
if (elementsVisited !== 3) {
$ERROR('#2: deleted elements should be visited');
}
elementsVisited = 0;
[1, 'string', 2].find(function (v, i, arr) {
elementsVisited++;
var stringIndex = arr.indexOf('string');
if (stringIndex !== -1) arr.splice(stringIndex, 1);
if (v === 'string') {
$ERROR('#3: \'string\' should not exist, it has been deleted');
}
if (v === undefined) {
$ERROR('#4: deleted element should not be visited');
}
});
if (elementsVisited !== 3) {
$ERROR('#4: deleted elements should be visited');
}