Espruino/tests/test_array_remove.js
Michael Duerinckx 7f5308590b Rename numbered tests to something more descriptive - closes #16
test077 is the only one I really couldn't figure out what it was meant
to test.
2014-03-01 22:15:28 +00:00

18 lines
416 B
JavaScript

// test for array remove
// note: array.remove does not exist in the JavaScript standard
Array.prototype.remove = function(x) {
var idx = this.indexOf(x);
if (idx<0) return; // not in array
var l = this.length;
for (var i=idx+1;i<l;i++)
this[i-1]=this[i];
this.pop(); // pop off the old value
}
var a = [1,2,4,5,7];
a.remove(2);
a.remove(5);
result = a.length==3 && a[0]==1 && a[1]==4 && a[2]==7;