+ 1
Can anyone help me in fixing the problem?
I'm not getting the correct max value in this code https://code.sololearn.com/Wa15a25A23a2/?ref=app
4 Answers
+ 2
Hey there Sai Ganesh Darni ,
I'm not able to help you because every time I open the code in my phone, SoloLearn crashes.
Try to have a look at this:
https://www.sololearn.com/discuss/2707837/?ref=app
Do you created this code in pc (Sl website)? đ€
If yes, then the solution is, go on Sl website on phone, copy and paste it on app :)
0
The syntax
(23, 12, ...)
does not work as you are expecting it to. Contrary to what it may look like, it won't make a collection of numbers. comma (,) is a valid operator in JavaScript and it simply returns the right hand side of the expression. For example
12, 13
returns 13, and
10, 3
returns 3. That is why, in your code, if youdisplay the value of`c`, it will always output -211, and hence Math.min/max(c) will also always give -211.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator
Maybe you wanted to use square brackets instead of parantheses? Like so
[23, 12, ...]
Then again, passing an array to Math.min/max does not work. You will need to unpack the array using the spread operator like so
Math.min(...c)
0
The Spread Operator
What is the output of the following code?
let nums = [3, 4, 5];
let all = [1, 2, ...nums, 6];
console.log(all[3]);
0
it's 4