Coder Social home page Coder Social logo

elements-kinds's People

Watchers

 avatar  avatar

elements-kinds's Issues

Incorrect `containsHoles` implementation

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.

Incorrect Smi range

isSMI currently uses Number.isMaxSafeInteger which goes all the way to 2**53-1:

elements-kinds/index.js

Lines 10 to 12 in 2d96ef5

function isSMI(arr) {
return arr.every(e => Number.isSafeInteger(e) && !Object.is(e, -0));
}

However, the actual Smi range is Signed31 on 32-bit architectures and Signed32 on 64-bit architectures. Since the last bit is used to distinguish positive and negative numbers, that leaves 30 or 31 bits for the actual numeric value, respectively.

On my machine (64-bit):

%DebugPrint([2**31-1]);
// → PACKED_SMI_ELEMENTS
%DebugPrint([2**31]);
// → PACKED_DOUBLE_ELEMENTS

`isDouble` doesn’t actually check for doubles

isDouble just checks for numbers:

elements-kinds/index.js

Lines 14 to 23 in 2d96ef5

/**
* Handles +-Infinity, Doubles, NaN, -0
*/
function isDouble(arr) {
return arr.every(e => typeof e === "number");
//return arr.some(
// e =>
// Number.isNaN(e) || (Number(e) === e && e % 1 !== 0) || Object.is(e, -0)
// );
}

This appears to work fine because of the ordering used here, where isDouble is only used if it’s not an array of Smis:

elements-kinds/index.js

Lines 46 to 50 in 2d96ef5

if (isSMI(inputArray)) {
kind = ELEMENTS_KINDS.HOLEY_SMI_ELEMENTS;
} else if (isDouble(inputArray)) {
kind = ELEMENTS_KINDS.HOLEY_DOUBLE_ELEMENTS;
} else {

Suggested fix: either rename isDouble to isNumber, or actually check for double values :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.