From 43b44747c2876e3fbf5d3945248357872af6c61a Mon Sep 17 00:00:00 2001 From: Yuji Yoneda Date: Wed, 5 Jan 2022 13:49:31 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E9=9A=8E=E4=B9=97=E8=A8=88=E7=AE=97?= =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app.js b/app.js index ab9c9ba8..58c1b79a 100644 --- a/app.js +++ b/app.js @@ -8,6 +8,13 @@ function factorial(n) { let result = 1; // TODO このコメントを消して正しく実装してください。 + // n = 5 + // result = 5 * 4 * 3 * 2 * 1 + // result = n * (n - 1) * (n - 2) * (n - 3) * (n - 4) + // result = result * (n - i) + for(let i = 1; i <= n; i++){ + result = result * i; + } return result; } const assert = require('assert'); From 621e30060ba0dd95528e9738d22c1e31528a08c1 Mon Sep 17 00:00:00 2001 From: Yuji Yoneda Date: Wed, 5 Jan 2022 14:00:11 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app.js b/app.js index 58c1b79a..37ed9fc6 100644 --- a/app.js +++ b/app.js @@ -7,11 +7,7 @@ */ function factorial(n) { let result = 1; - // TODO このコメントを消して正しく実装してください。 - // n = 5 - // result = 5 * 4 * 3 * 2 * 1 - // result = n * (n - 1) * (n - 2) * (n - 3) * (n - 4) - // result = result * (n - i) + // 階乗計算 for(let i = 1; i <= n; i++){ result = result * i; }