const coinArr = [500, 100, 50, 10] let N = 1260 let count = 0 for (const coin of coinArr) { count += Math.floor(N / coin) N = N % coin } console.log(count);