Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Chrome 126
Mac OS X 10.15.7
Desktop
10 months ago
Test name Executions per second
with reduce() 402372.2 Ops/sec
with sort() 450401.0 Ops/sec
HTML Preparation code:
AخA
 
1
<div id='min-data'></div>
Tests:
  • with reduce()

    x
     
    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();
  • with sort()

     
    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();