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.
this is NOT best practice, it modifies given data
!! is used to convert a truthy/falsy value to its boolean equivalent.
let num = 5; (truthy)
!num // false
!!num // true
let num = 0; (falsy)
!num // true
!!num // false
comparing 5 with !!5 would be the equivalent of comparing 5 with true (which is false)
5 === !!5
5 === true
The only reason people still use it over Boolean (other than wanting to look like elite hackers) is because it's something like 10-15% faster (last time I checked)
Nice idea. But it doesn't work with all values in JS. For example it returns true with 1 and 2
From description:
""xor" only returns true if EXACTLY one of the two expressions evaluate to true."
What's that? :b
Yes, you are right. It sorts in place.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
My first attempt was to try and return l.reverse(). I kept getting "None" as a result. Can someone explain why you have to do l.reverse() then return l instead of return l.reverse()?
This solution certainly solves the kata.
I only commented because this solution has a number of "best practices" votes.
Per the kata description:
"...a function that takes in a list and returns a list with the revese order."
In a function with that description modifying the passed in list is not "best practices"
If I could cast a down vote for "best practices" I would have done that instead of leaving a comment.
Which solution is "much better" depends on the purpose of reversing the list.
If you're done with the old list, this method is probably better as it doesn't leave the old list in memory. The kata instructions weren't clear about whether the old one needed to be preserved, so either approach should be fine.
This comment is hidden because it contains spoiler information about the solution
This one has the side effect of modifying the passed in list.
I would be much better to copy the list before reversing it.