LoginSignup
1
0

More than 5 years have passed since last update.

既約分数

Posted at

lowest terms | CreateJS

分数を「既約分数」として表示するための関数

////////////////////////////////////////
// 既約分数の取得
////////////////////////////////////////
function getLowestTerms(a, b) {
    var ta = a;
    var tb = b;
    var d;
    while (d = b%a) {
        b = a;
        a = d;
    }
    ta /= a;
    tb /= a;
    return {a: ta, b: tb};
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0