JSFiddle - React, Tailwind, and code Playground

by emilcieslar

JavaScript

const that = { get: () => [{}, {}, {}, {}] };

function something1(){const t=that.get("contentUnit.data.steps");if(t&&t.length){return t.find(t=>t.is_root)}return null}

function something2(){return(that.get("contentUnit.data.steps")||[]).find(t=>t.is_root)}


var t1_0 = performance.now();
something1();
var t1_1 = performance.now();

var t2_0 = performance.now();
something2();
var t2_1 = performance.now();


alert("Call to something1 took " + (t1_1 - t1_0) + " milliseconds.");
alert("Call to something2 took " + (t2_1 - t2_0) + " milliseconds.");