vigneshshanmugam/elements-kinds

Incorrect `containsHoles` implementation

Closed this issue · 1 comments

The current containsHoles implementation seems to check for undefined values:

elements-kinds/index.js

Lines 25 to 32 in 2d96ef5

function containsHoles(arr) {
for (const ele of arr) {
if (typeof ele === "undefined") {
return true;
}
}
return false;
}

Holes are something else, though!

  • [undefined, undefined, undefined] is a packed array that happens to contain undefined values.
  • Examples of holey arrays are [1,,2], x = [1, 2, 3]; delete x[1], new Array(10), and x = []; x[42] = 1.

You can detect holes by using the in operator, or by using hasOwnProperty.

Thanks a lot for the feedback @mathiasbynens. Nice catch, totally missed it.

Changed the implementation #4