Script – 00-49 Jan 31

I'm very confused at this occurrence derp How is
if (grid[0].sort()) {
console.log(true)
}
if (grid[0].sort()) {
console.log(true)
}
actually sorting grid[0]?
S
Script809d ago
is that a normal thing? I do not understand whats going on
UU
Unknown User809d ago
S
Script809d ago
the if statement is actually sorting grid whereas I'm just trying to check if grid is sorted
A
acemarke809d ago
yes, because you're calling .sort(), and the if statement is comparing what that returns .sort() does not do any kind of a "is this sorted?" check
UU
Unknown User809d ago
A
acemarke809d ago
and there really isn't an easy way to check if an array is sorted at least not any kind of built-in API
UU
Unknown User809d ago
S
Script809d ago
and this exercise says to do so
S
Script809d ago
taking a look at this.
A
acemarke809d ago
yeah, so at that point you have to do something like what iggy showed the point is that there is no generic "is this sorted" function the answer to "is this sorted" entirely depends on what is inside the array, and that's specific to your app so yeah, you most likely would need to do some kind of pairwise comparisons all the way down the array
UU
Unknown User808d ago