frequency Counter :: Write a function called sameFrequency. Given two positive integers, find out if the two numbers have the same frequency of digits.

329


frequency Counter ::

Following is sample javascript code.


// Your solution MUST have the following complexities: 
// Time: O(N)
// Sample Input:

// sameFrequency(182,281) // true
// sameFrequency(34,14) // false
// sameFrequency(3589578, 5879385) // true
// sameFrequency(22,222) // false

function sameFrequency(num1, num2) {
  let strNum1 = num1.toString();
  let strNum2 = num2.toString();
  if(strNum1.length  !== strNum1.length ) {
    return false
  }
  let feqquency = {num1:{}, num2:{}, result:0}
  for(let i = 0; i < strNum1.length; i++) {
    feqquency.num1[strNum1[i]] = strNum1[i]
    feqquency.num2[strNum2[i]] = strNum2[i]
    
  }
  
  for(let j = 0; j < strNum1.length; j++) {
    if(feqquency.num1[strNum1[j]] === feqquency.num2[strNum1[j]]){
      feqquency.result += 1;
    }
  }
  
  return feqquency.result === strNum1.length ? true:false
  console.log(feqquency)
}
console.log(sameFrequency(182,287))