Test name | Executions per second |
---|---|
with reduce() | 371129.1 Ops/sec |
with sort() | 390799.7 Ops/sec |
<div id='min-data'></div>
const div = document.getElementById('min-data');
const newArray = [];
for(let i = 0; i < 10; i++){
const num = Math.floor(Math.random() * 10);
newArray.push(num);
}
newArray.reduce((a, b) => (a < b ? a : b), []);
div.innerHTML = newArray[0].toString();
const div = document.getElementById('min-data');
const newArray = [];
for(let i = 0; i < 10; i++){
const num = Math.floor(Math.random() * 10);
newArray.push(num);
}
newArray.sort((a, b) => a - b);
div.innerHTML = newArray[0].toString();