JS: analyze performance time for your code
Link: Console.time() & Console.timeEnd()
console.time("Time this"); //start with console.time with a string argument then provide code after
function sameFrequency(arg1, arg2){
if (arg1.toString().length !== arg2.toString().length) return false;
let countObj = {};
for (let num of arg1.toString()) {
if (countObj[num]) countObj[num]++;
else countObj[num] = 1;
}
for (let item of arg2.toString()) {
if (!countObj[item]) return false;
else countObj[item]--;
}
for (let item in countObj) {
if (countObj[item] > 0) return false;
return true;
}
};
console.timeEnd("Time this"); //end with console.timeEnd with same string argument
Comments
Post a Comment