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

Popular posts from this blog

Code Wars: Data Reverse (6 kyu)

Code Wars: longest_palindrome (6 kyu)

Code Wars: Find the odd int