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

View File

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