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 comment is hidden because it contains spoiler information about the solution
This has O(n^2) time complexity
You probably don't need the answer as of now. You might not even see this comment. But to anyone who is interested in the explanation, here it is:
Storing an object as a key inside of an another object doesn't really work. Object keys in javascript are type of String (Even when you access a property of an object using a number i.e. obj[1] javacsript internally converts it to a String type). And since keys in an object should be of type string any object that is used as a key inside of another object will be turned into "[object Object]". That's why the check on line 4 fails to distinguish the other objects. The solution should work with maps though. Unlike in objects, you can use objects as keys in maps. For additional info on maps: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
Acording to my peformance tests the one with sum and map is most time efficient, i was not expecting it to be so comparing to pure loops, but i guess we are better off using built-in functions?
PS: i had solved it like this as well...
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Just a suggestion for next time to save on time and space:
Instead of splitting the message into an array, you can use a
for ... of
loop to cycle through the letters one at a time.The code would look as follows:
for (let c of message) {...
Following. would love to know as well
This comment is hidden because it contains spoiler information about the solution
Lol.. I spent longer than I'd like to admit trying to wrap my head around it as well :(
This comment is hidden because it contains spoiler information about the solution
@CodedVortex thank you for this explanation, I didn't know that using
Array
was not best practice.Barring when it is not used correctly, does the literal notation have any performance benefits over calling the constructor? (i.e. any time/space-related metrics.)
The /../ part of the code represents a Regular Expression (RegEx) that looks for any 2 types of characters. If the length is even, When it comes time to check for the last character (i.e. the underscore) it will not be able to find another character after it, and thus won't add it to the resulting array.
How would you put squares [14, 9, 1, 1, 1] together to form a rectangle?
Loading more items...