Created
April 7, 2016 08:10
-
-
Save nekonenene/a1794022bb5a3ce3e930b5dd2b9c42ff to your computer and use it in GitHub Desktop.
ES6 を用いたユークリッド互除法。しかし displayGcd メソッド内のログ出力は undefined となる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() | |
{ | |
var gcd = new GreatestCommonDivisor(14, 21); | |
var outputElement = $(".output"); | |
outputElement.append( gcd.displayGcd() ); | |
}); | |
class GreatestCommonDivisor | |
{ | |
constructor(_a = 1, _b = 1) | |
{ | |
this.a = _a; | |
this.b = _b; | |
} | |
/* ユークリッド互除法で最大公約数を求め、返す */ | |
static euclid(_a, _b) | |
{ | |
var a = _a; var b = _b; | |
var remainder = a % b; | |
// console.log(remainder + " : " + b); | |
if(parseInt(remainder) === 0) | |
{ | |
return parseInt(b); | |
} | |
this.euclid(b, remainder); | |
} | |
/* 最大公約数を案内する文字列を返す */ | |
displayGcd() | |
{ | |
var gcd = GreatestCommonDivisor.euclid(this.a, this.b); | |
console.log( gcd ); | |
var string = this.a + " と " + this.b + " の最大公約数は " + gcd; | |
return string; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
こんにちは。
return
が抜けているようです。Babel