I'm studying this JS function:
function solution (array, commands) {
return commands.map (v => {
return array.slice(v[0] -1, v[1]).sort((a, b) => a - b).slice(v[2] -1, v[2])[0];
});
}
I do not know what v[0] -1 does.
If commands is a two-dimensional array like this:
[[2,5,4] [4,4,1] [1,7,3]]
What does v[0] mean and what does it mean to do -1 to it like v[0] -1?
mapiterates through each item incommands. The current iteration/item isv. Therefore,v[0]would refer to the first item in one of child arrays.