Ad
  • Default User Avatar

    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.

  • Default User Avatar

    Objects {}, Arrays [], Functions function () {} 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.