Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

階乗関数の実装 #3049

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
*/
function factorial(n) {
let result = 1;
// TODO このコメントを消して正しく実装してください。
for (let i = 1; i <= n; i++){
result = result * i;
}
return result;
}
const assert = require('assert');
assert.equal(factorial(1), 1, `1の階乗は1ですが、実際は${factorial(1) }でした`);
assert.equal(factorial(2), 2, `2の階乗は2ですが、実際は${factorial(2) }でした`);
assert.equal(factorial(3), 6, `3の階乗は6ですが、実際は${factorial(3) }でした`);
assert.equal(factorial(4), 24, `4の階乗は24ですが、実際は${factorial(4) }でした`);
assert.equal(factorial(5), 120, `5の階乗は120ですが、実際は${factorial(5) }でした`);
assert.equal(factorial(6), 720, `6の階乗は720ですが、実際は${factorial(6) }でした`);
assert.equal(factorial(7), 5040, `7の階乗は5040ですが、実際は${factorial(7) }でした`);
assert.equal(factorial(8), 40320, `8の階乗は40320ですが、実際は${factorial(8) }でした`);
assert.equal(factorial(9), 362880, `9の階乗は362880ですが、実際は${factorial(9) }でした`);
assert.equal(factorial(10), 3628800, `10の階乗は3628800ですが、実際は${factorial(10) }でした`);
console.log('すべてのテストを通過しました');
console.log('すべてのテストを通過しました');