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.
To add to this, you can see what this looks like by doing a
console.log()
on the object after you have added keys to them. You'll see that the key's are simply a string of numbers, not actual numbers.you can't store actual numbers as keys in object. so javascript automatically converts them to string when assigned to an object as a key
There is no reason to store the non odd occuring numbers. Doing so requires you to loop through again and find the odds. It's much slower than deleting a key if it's already in the object
This solution has a run time of O(n). Since the run time of a sorting algorithm is usually O(nlogn), and you'd still have to iterate through your array once more to count the number of times the integer appears, this solution would be faster.
prop is a string
Yes, similiar as mine, but much much shorter and more readable :) kudos
This comment is hidden because it contains spoiler information about the solution
I don't quite understand what you mean, you mean if obj[el] is non-existent, delete obj[el]?
But the question is we need to find out the odd one, not only the only one.
not enought good because two loops instead of one. One loop is enought (use
delete
instead of= 1
and then get the only object field).May i know what does Number(prop) do? where can i read more on this?
This comment is hidden because it contains spoiler information about the solution
Thank you for reply, btw I cannot understand how obj[el] returns boolean value?
If
obj[el]
exists, increment is by one, if not set it to 1.I had the same solution... great minds think alike!
#nice#
Loading more items...