Skip to content

Commit 4903b1d

Browse files
authored
Create 972-equal-rational-numbers.js
1 parent 736f66a commit 4903b1d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

972-equal-rational-numbers.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {string} S
3+
* @param {string} T
4+
* @return {boolean}
5+
*/
6+
const isRationalEqual = function (S, T) {
7+
return f(S) === f(T)
8+
}
9+
10+
function f(S) {
11+
let i = S.indexOf('(')
12+
if (i > 0) {
13+
let base = S.slice(0, i)
14+
let rep = S.slice(i + 1, S.length - 1)
15+
for (let j = 0; j < 20; ++j) base += rep
16+
return +base
17+
}
18+
return +S
19+
}

0 commit comments

Comments
 (0)