I have been having some problems with this JS code.
The code is supposed to generate an array of random voltages (in the volts array), and then create a new array (the sortedVolts array) where the volts are sorted by lowest to highest.
The problem is that my code is sorting not only the sortedVolts array, but also the volts array, which is supposed to remain unsorted. Why is this happening?
var volts = [];
var sortedVolts;
for (var count = 0; count < 3; count++) {
volts.push(Math.floor(Math.random() * 100));
}
sortedVolts = volts;
sortedVolts.sort();
console.log('UNSORTED', volts);
console.log('SORTED', sortedVolts);