The first part worked for me! And to each their own right? Because I totally understood the first solution but got lost in the 2nd solution. Thanks for sharing!
@AdyNgom4 жыл бұрын
Glad it was helpful Alexandra. Cheers
@rodmm30104 жыл бұрын
they target different problems. first one just build up pairs.second one actually build groups.
@aslancanylmaz72944 жыл бұрын
there is an app that has hackerrank's all javascript solutions, and u can copy the code. "Hackerrank JS"
@fahadzakir63975 жыл бұрын
The first solution did not pass all the hacker rank test, and the 2nd one did. The first solution was a lot easier to understand than the 2nd solution I did not understand the bottom part with n in it.
@rashad123us5 жыл бұрын
It takes the the values from the dictionary he built using the reduce array method, divides them in half then rounds down using parseint. So you only add the colors with 1 or more pairs to the pairs count. Its pretty simple, and more efficient.
@rodmm30104 жыл бұрын
Second solution is correct and nice. with the use of keys and works in every scenario. first solution not right. Will not work with constraints. Not a valid solution for hackerrank test. Also it just put pairs toghether. it is not creating differentarrays or objects with all the equal values. Just puts pairs together not arrays of same value items. Example if you had an array like let arr= [1,1,1,1] It will make 2 pairs of [1,1] instead of grouping all of them into one array. Why would i want to have 2 arrays of [1,1]??