Nice syntax solution. But why you are using every() function. Isnt it more efficient to stop after the first matched negative value ?
+1 for readability and best practice, but this answer violates the specified constraints, which were implied by the message "answer goes here" placed between a single pair of slashes.
I like this. the j = i + 1 is what I like. Reduces the iterations whilst not requiring an identical index check.
Thanks for your explanation a lot.
So, what you mean is that 'this' of vasya's method (if passed to the .every() just as vasya.sell) will be bound to the personInLine which, in return, will not have 'money' object inside causing an error?
If so, then I got it. But it took me some time.
Because vasya.sell is just the function ( Function Object ), unexecuted, unbound.
If you want to execute that function with this bound to vasya, you have to bind it and then later execute it, or execute the function as vasya.sell($something) in one expression.
There is a difference between .every( vasya.sell ) and .every( personInLine => vasya.sell(personInLine) ). Maybe there need not have been a difference, but there is. There's something to be said for ( and against ) both possibilities.
.every( vasya.sell )
.every( personInLine => vasya.sell(personInLine) )
Really nice solution!
This code does not work with non-latin text.
Isn't it a bit overcomplicated for the task? Why wrapping the solution into an object with functions is so upvoted as a best practice, where just a switch seems to be enough?
This answer is neither best practice or clever
Why not good practice?
Why not clever?
Looking at the comments, I am beating the dead horse here, but since there is no way to down vote I feel it is required to express how bad the most top voted solution is...
arr.Sum(), I was looking for something like that! Thanks!
This comment is hidden because it contains spoiler information about the solution
it's because there never be a situation when the clerk should give change from 100; there always less than 100. f.e 100-25 = 75