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

Flip order of arguments #16

Open
Richienb opened this issue Aug 30, 2020 · 2 comments
Open

Flip order of arguments #16

Richienb opened this issue Aug 30, 2020 · 2 comments

Comments

@Richienb
Copy link

Richienb commented Aug 30, 2020

It's best if the arguments were the other way around to avoid readability issues with long arrays:

const closestNumber = require('closest-number');

closestNumber(12, [10, 20, 30, 40, 50, 60, 70]);
// => 10

// @andreruffert

@andreruffert
Copy link
Owner

andreruffert commented Aug 31, 2020

Ideally you would define the array of numbers in a separate constant even with a flipped order of the arguments.
That's why I think this change would not really bring any benefits.

const closestNumber = require('closest-number');

const arrayOfNumbers = [10, 20, 30];
const value = 12;
const result = closestNumber(arrayOfNumbers, value);
// => 10

Might be worth updating the README. What do you think?
I'm open for a discussion in case I missed something. ✌️

@Richienb
Copy link
Author

Many functions in the javascript prototype were designed with the incorrect order of arguments. For instance, in Array#reduce, the array is taken as the final argument even though it is the first thing you need to know to understand the function. Ideally, it is best for the first argument in closestNumber to be the actual number since that is the first thing needed to understand the expression.

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

No branches or pull requests

2 participants