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.
I wanted to add some additional notes due to OOP, but they were unnecessary anyway. Undid the changes ✅
The best javascript book I've read is Javascript: The Good Parts (Edit: and fyi that guy is very strict with his own version of best practices). However, you want to have some programming background before you go about reading it. There are other languages you can try out here, and knowing more than one language definitely helps with dealing with nuances in any language.
Objects
{}
, Arrays[]
, Functionsfunction () {}
and RegExps//
are all literals that are compared by reference. Basically, if you're saying one array or object is equal to another, they need to be the same reference (i.e. two different arrays are treated like identical twins with different identities, even though they look the same). There are a few other funky things about that regarding methods like slice and sort where the return value still references the pre-existing array in some manner. Definitely something to read up on.One problem with your solution is that you're using a for-in style loop. That style loop goes over all properties of an object (for an array it includes length). It's best practice to avoid that unless you're dealing with an object literal (and even then there are further best practices).
Another thing to watch out for is modifying the original array; again, it's best practice. You should test to ensure that the original array is not the same as the one returned from the function (you can do that with Test.assertEquals).
Finally, the correct function to use here would be Test.assertSimilar.