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.
Lol what? He used sort which is a built in function, also his solution is O(nlogn) when the optimal solution is O(n)
so use the reduce is optimial because O(n) ?
nice try
This is O(n logn). The optimal is O(n).
I basically created an extra variable for no reason. -______-
Great Job.
This is what I consider clever, not using the built in function.
same
Didn't think of that. Good Point! Also like your solution using the spread operator.
Mutating the parameter ... ouch!
I feel like you're splitting hairs. NaN, literally not a number, is of type number because there is no other primal it could be attached to. Would it be attached to a string? Array? Boolean?
From the ECMA 2015 specfications it says that NaN is "number value that is an IEEE 754-2008 'Not-a-Number' value." What about positive and negative infinity? Those are also "number" values that don't directly relate to a number but are under the number primals.
You should either specify that non-numerical number types should be accounted for or admit that your test case was ill-concieved and that it's illogical to try and add NaN, infinity, or -infinity.
According to javascript NaN is a number so... even If I don't like it too the sum of number NaN plus number 2 is NaN. Yes ironically the constant for Not A Number is of type.... number!!!.
typeof NaN === "number" //true
the question states that anything other than a numbers should add 0, now when an array only have NaN the expected output in my view is 0 as its not a number and cannot be added.
could the tests be changed or requirement be specified more clearly?
Also it looks like a pattern where you are passing NaN or null the expected output in the test becomes NaN instead of the sum of other numbers
In the current test it expects an output of NaN.
Ex: 1
initial array [ NaN ]
Expected: NaN, instead got: 0
Ex: 2
initial array [ NaN, 6, {}, 67, 934 ]
total 1007 binary 1111101111
Expected: NaN, instead got: 1111101111
but if we add all the numbers above we get 1007, i am not sure if i am missing anything here.