function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function curveScore(original, curveAmount) {
return original + curveAmount;
}
//Generate a random array
const testScores = Array.from({
length: 20
}, () => getRandomIntInclusive(60, 100));
console.log(testScores);
// Updated testScores with curved scores
testScores.forEach((el, i, curvedScores) => {
curvedScores[i] = curveScore(el, 10);
});
console.log(testScores);
So, everything works fine here. Essentially, a random array of 'test scores' is generated, and those scores are logged, then 'curved' by 10 points, and then logged again.
The interesting thing is that the first time I open this in the browser, I don't get the proper results. The same Array is displayed 2x (no 10 points added).
Once I refresh browser, then I get the correct output.
Why? I guess somehow console.log()
is firing 2x before forEach()
is finished? Would this require a Promise or something to display the proper results consistently?