-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (31 loc) · 869 Bytes
/
index.js
File metadata and controls
39 lines (31 loc) · 869 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
36
37
38
console.log(tableTo(20));
function tableTo(to, from = 1) {
if(typeof to !== "number" || typeof from !== "number") {return null;}
let wholeTable = [];
for (let index = from; index < to + 1; index++) {
const table = getTable(index);
wholeTable.push(table);
}
return wholeTable;
}
// console.log(getTable(2));
function getTable(num) {
if(typeof num !== "number") {return null;}
let table = [];
const tableArray = getTableArray(num);
tableArray.forEach(function (item, index) {
const tableItem = `${num} x ${index + 1} = ${item}`;
table.push(tableItem);
});
return table;
}
// console.log(getTableArray(2));
function getTableArray(num = 1) {
if(typeof num !== "number") {return null;}
let tableArray = [];
for (let i = 1; i < 11; i++) {
const result = num * i;
tableArray.push(result);
}
return tableArray;
}