Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array indexing implementation ... minor code review suggestion #184

Closed
michaelthoward opened this issue Apr 1, 2018 · 1 comment · Fixed by #222
Closed

array indexing implementation ... minor code review suggestion #184

michaelthoward opened this issue Apr 1, 2018 · 1 comment · Fixed by #222

Comments

@michaelthoward
Copy link

In the process of familiarizing myself with jsonata.js I ran across the following ...

The JSONata documentation states that non-integer array indexes are rounded down in Navigating JSON Arrays.

In applyPredicates() and evaluateFilter(), the predicate Number.isInteger() is used to determine whether or not Math.floor() should be called. The implementation of Number.isInteger() itself ends up using Math.floor() ... either implicitly or explicitly.

I suggest that it would be simpler and more efficient to simply call Math.floor() directly:

if (!Number.isInteger(ires)) {
// round it down
ires = Math.floor(ires);
}

becomes

ires = Math.floor(ires)

@andrew-coleman
Copy link
Member

Good point. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants