We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I'm still new to Javascript, can you explain what your nested terinary operators are doing? My best guess understanding is:
m means "Max" c is standing in for "current" like the accumulator in the reduce function. v is the value in the array we are currently looking at.
I'm used to seeing a 2 paramater reduce as:
param 1 – the value from the last time we iterated through the array, index 0 on the first go around and param2 - the hing in the array we are working on through THIS iteration.
So it seams to be we are saying, "Okay, if this current array value is the biggest we've seen, then set max to that and increase current, else... and then I'm confused about what is being spit out in the else condition. I see a variable and a 0 separated by a comma? I know a function cannot return 2 values without spitting out an object or an array so what is the reduce function doing with m and c and in the else condition? Then obviously the whole thing resolves to an even or odd number and the modulos tell us which player we landed on, but the else is really tripping me up,. My limited understanding of the reduce higher order function has me confused about what's happening here.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Gaming Array 1
You are viewing a single comment's thread. Return to all comments →
I'm still new to Javascript, can you explain what your nested terinary operators are doing? My best guess understanding is: m means "Max" c is standing in for "current" like the accumulator in the reduce function. v is the value in the array we are currently looking at.
I'm used to seeing a 2 paramater reduce as: param 1 – the value from the last time we iterated through the array, index 0 on the first go around and param2 - the hing in the array we are working on through THIS iteration.
So it seams to be we are saying, "Okay, if this current array value is the biggest we've seen, then set max to that and increase current, else... and then I'm confused about what is being spit out in the else condition. I see a variable and a 0 separated by a comma? I know a function cannot return 2 values without spitting out an object or an array so what is the reduce function doing with m and c and in the else condition? Then obviously the whole thing resolves to an even or odd number and the modulos tell us which player we landed on, but the else is really tripping me up,. My limited understanding of the reduce higher order function has me confused about what's happening here.