JSFiddle - React, Tailwind, and code Playground

by Trevor Power

JavaScript

function methodA(row)
{
   const rowLen = row.length;
   return row.map((rank, i) => {
     if (rowLen === i + 1) {
       // last one
     } else {
       // not last one
     }
   })
}

function methodB(arr)
{
   const lastIndex = arr.length - 1

   arr.map((el, i) => {
      if (i === lastIndex) {
         // last one
      } else {
         // not last one
      }
   })
}

function test(method){
   const arr = [1,2,3,4,5,6,7,8,9];
   
   document.body.innerHTML += 'working';
   
   const t0 = performance.now();

   for(var i = 0; i < 5000; i++)
   {
      method(arr);
   }

   const t1 = performance.now();

   document.body.innerHTML += ': ' + (t1 - t0) + " milliseconds.")
;
}



test(methodA)
test(methodB)