내 풀이
/*
문제
write a function called sameFrequency.
Given two positive integers,
find out if the two number have the
same frequency of digits.
Your solution MUST have the following complexities:
Time: O(N)
*/
function sameFrequency(a, b) {
let arrA = String(a)
.split('')
.map((num) => {
return String(num);
});
let arrB = String(b)
.split('')
.map((num) => {
return String(num);
});
return JSON.stringify(arrA.sort()) === JSON.stringify(arrB.sort());
}
console.log(sameFrequency(182, 281)); // true
console.log(sameFrequency(34, 14)); // false
console.log(sameFrequency(3589578, 5879385)); // true
console.log(sameFrequency(22, 222)); // false
조금 더 좋은 방법이 있을 것 같긴 한데, 일단 O(N)으로 풀었다.