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

multi関数定義 #2091

Open
wants to merge 1 commit into
base: master-2020
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
17 changes: 15 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
'use strict';
"use strict";
function add(numbers) {
let result = 0;
for (let num of numbers) {
result = result + num;
}
return result;
}
module.exports = { add };

function multi(numbers) {
let result = 1;
for (let num of numbers) {
result = result * num;
}
return result;
}
module.exports = { add, multi };

// require('sum') としているのは、sum ライブラリを読み込むためです。
// sum というラブラリを作成したのでそれを読み込んでいます。

// intro-curriculum-3004はフォルダー名で、ライブラル名が npm init した時にきめます。以下の URL から package.json ファイルを見て見ますと、name: 'sum' となっているのが確認できるかと思います。