Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
'Looks like you've solved it'
.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
"To compare numbers instead of strings, the compare function can simply subtract b from a."
I was baffled why my test cases hadn't come through but realised where the correct input box was on the edit page, thanks for the heads up!
You should carefully walk through the logic you have built here and consider what the result will be in each possible test case you can imagine. For instance,
remainder(0, -5)
should actually return0
(but it seems I missed that test case in the kata itself). In the case where the input values are equal, your logic ends up returninga || b
, which doesn't make any sense.This comment is hidden because it contains spoiler information about the solution
Because the method will never modify anything. It's defined like this.
Take a look at Array#Iteration_methods to see how to use
Array#some
( * and if maybe there's a better method to solve this kata * )The method you're using doesn't modify the object. Instead, it returns a new one.
What do you get? A string. What do you return? A string. That's not what you're asked for, the kata asks for a number. The types don't match.
Hint: save or return the result of your function call.
@ZozoFouchtra: Marked your comment as spoiler.
This comment is hidden because it contains spoiler information about the solution
hints:
about arguments, you may use
.length
to get last one (like you useArray#length
in your code :myArray[myArray.length - 1]
)more info about if...else
. . . is a bad construction, you should use :
. . . or :
Other than that don't forget there may be
last
should return the last argument.eg :
Happy coding!
The Push basically pushes an element into the array here is some documentation on the method push
it creates a new array with the result of calling given function on every element of this array. Which it will add "Hello" + your arguments + "!"