Karl Morrison Karl Morrison - 2 months ago 6x
Javascript Question

Translate row in Python to JavaScript: [(M[i], k // M[i])]

I'm trying to translate the following script into JavaScript. There is one row which I have no idea what it does, I'm suspecting push to the array.

def greedyCoinChanging(M, k):
n = len(M)
result = []
for i in xrange(n - 1, -1, -1):
result += [(M[i], k // M[i])] // <-- what the hell is this in JavaScript?
k %= M[i]
return result


In JavaScript, you don't have to use a tuple. You can just use an array.

result.push([M[i], Math.floor(k/M[i])]);

Also, the integer division (//) can become Math.floor(k/M[i]);