-
Notifications
You must be signed in to change notification settings - Fork 0
/
s6-ex3.js
55 lines (47 loc) · 943 Bytes
/
s6-ex3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function sameFrequency(a, b){
let x = a.toString();
let y = b.toString();
var xA = {};
var yA = {};
if (x.length != y.length)
{
return false;
}
for (let i = 0; i < x.length; i++)
{
let s = x[i];
if (xA[s])
{
xA[s]++;
}
else
{
xA[s] = 1;
}
}
for (let i = 0; i < y.length; i++)
{
let s = y[i];
if (yA[s])
{
yA[s]++;
}
else
{
yA[s] = 1;
}
}
for (let i = 0; i < x.length; i++)
{
let s = x[i];
if (xA[s] != yA[s])
{
return false;
}
}
return true;
}
console.log(sameFrequency(182, 281)); // True
console.log(sameFrequency(34, 14)); // False
console.log(sameFrequency(3589578, 5879385)); // True
console.log(sameFrequency(22, 222)); // False