Script
Script3y ago

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]?
12 Replies
Script
ScriptOP3y ago
is that a normal thing? I do not understand whats going on
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Script
ScriptOP3y ago
the if statement is actually sorting grid whereas I'm just trying to check if grid is sorted
acemarke
acemarke3y 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
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
acemarke
acemarke3y 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
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Script
ScriptOP3y ago
and this exercise says to do so
Script
ScriptOP3y ago
taking a look at this.
acemarke
acemarke3y 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
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
reactibot
reactibot3y ago
This question has an answer! Thank you for helping 😄 If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/937509918062288916 This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/937509918062288916

Did you find this page helpful?