I think you like to write mini stories, but... I lost myself few times... 2 hours took me to solve this... I don't think the mini-books should be on 8kyu lvl.
For clarify: return array.filter((x,i)=>array.lastIndexOf(x)===i)[0] is incorrect
It should be return array.filter(x=>array.indexOf(x)===array.lastIndexOf(x))[0]
Usually this is a reference message. It can help you determine what kind of code you are going to write. ;-) Of course, for this Kata, this information has no effect. But for some Kata, these information is your good friend ;-)
For example: In a kata, the task is to find a unique number in an array(only one number is unique).
If the author told you the length of array is less than 100. Well, return array.filter((x,i)=>array.lastIndexOf(x)===i)[0] is a valid solution. But If the author told you the length of array is more than 1000000, then you need to think about a O(n) solution to solve it. Because avoid code timeout has become a more important problem ;-)
I just wanted to make sure that there wasn't something fundamentally wrong with my understanding of the kata and the described constraints. I'm new to this, so I'd rather check now than work under false pretenses.
I agree with you. Some kata descriptions (and katas) could be improved. However as people do it for nothing, we can't really complain even though sometimes it can be a bit frustrating.
Hi @goatffc, AFAIK the intention of those constraints in the description was simply to say "here are the ranges of parameters that may be passed to your function", rather than "you must check these". i.e. The purpose is to make the Kata easier, not harder so you can concentrate on the solution instead of worrying about input validations... :-)
I think you like to write mini stories, but... I lost myself few times... 2 hours took me to solve this... I don't think the mini-books should be on 8kyu lvl.
thank you!!!! how did i not see that!!!! done it now!
to create a new array, don't modify arr
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
This comment is hidden because it contains spoiler information about the solution
For clarify:
return array.filter((x,i)=>array.lastIndexOf(x)===i)[0]
is incorrectIt should be
return array.filter(x=>array.indexOf(x)===array.lastIndexOf(x))[0]
I think the filter solution should be a O(n^2) solution.
If you want, welcome try to solve this sreies:
Find number in an array # 1
Find number in an array # 2
Find number in an array # 3
Find number in an array # 4
Find number in an array # 5
Find number in an array # 6
Out of interest, what is the filter solution called if the other type of solution is a O(n) solution?
What would the difference in speed be, of the one method over the other, for 1 million items?
Usually this is a reference message. It can help you determine what kind of code you are going to write. ;-) Of course, for this Kata, this information has no effect. But for some Kata, these information is your good friend ;-)
For example: In a kata, the task is to find a unique number in an array(only one number is unique).
If the author told you the length of array is less than 100. Well,
return array.filter((x,i)=>array.lastIndexOf(x)===i)[0]
is a valid solution. But If the author told you the length of array is more than 1000000, then you need to think about a O(n) solution to solve it. Because avoid code timeout has become a more important problem ;-)Gotcha. No complaints here.
I just wanted to make sure that there wasn't something fundamentally wrong with my understanding of the kata and the described constraints. I'm new to this, so I'd rather check now than work under false pretenses.
I agree with you. Some kata descriptions (and katas) could be improved. However as people do it for nothing, we can't really complain even though sometimes it can be a bit frustrating.
This comment is hidden because it contains spoiler information about the solution
Hi @goatffc, AFAIK the intention of those constraints in the description was simply to say "here are the ranges of parameters that may be passed to your function", rather than "you must check these". i.e. The purpose is to make the Kata easier, not harder so you can concentrate on the solution instead of worrying about input validations... :-)
Loading more items...