-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path01.js
More file actions
35 lines (32 loc) · 727 Bytes
/
01.js
File metadata and controls
35 lines (32 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* @func add
* @desc Addition entre l'argument a et b
* @param {!Number} a
* @param {!Number} b
* @returns {Number}
*
* @throws {TypeError}
*/
export function add(a, b = 10) {
if (typeof a !== "number") {
throw new TypeError("a must be a number");
}
if (typeof b !== "number") {
throw new TypeError("b must be a number");
}
return a + b;
}
/**
* @func calc_moy
* @desc Calcule d'une moyenne à partir d'un tableau de nombre
* @param {!Number[]} nums
* @returns {Number}
*
* @throws {TypeError}
*/
export function calc_moy(nums = []) {
if (!Array.isArray(nums)) {
throw new TypeError("nums must be an array!");
}
return nums.reduce((acc, curr) => curr + acc, 0) / nums.length;
}