When attempting to retrieve the value 2316, the result is [0,2,0,3,0,0,2,1,0,1] instead of the expected output [0,2,0,3,0,0,1,1,0,1]. It seems like there may be an issue with the algorithm I am using.
function findNoteAndCoins(salary) {
var note = [5000,1000,500,100,50,20,10,5,2,1];
var noteCount = new Array(10);
noteCount = Array.from(noteCount, item => item || 0);
for(var i = 0; i < 10; i++){
if (salary >= note[i]){
noteCount[i]= salary / note[i];
salary = salary % note[i];
}
}
for(var j = 0; j < 10; j++){
if (noteCount[j] != 0){
var count = noteCount[j];
}
}
return noteCount.map(num => (num * 1).toFixed(0));
}
findNoteAndCoins(2316);