function multiply first second function toInt array let result for let

 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
39
40
41
42
43
44
45
46
function multiply(first, second) {
function toInt(array) {
let result = [];
for (let i = 0; i < array.length; i++) {
result[i] = parseInt(array[i]);
}
return result;
}
function crutch(value) {
if (typeof value === 'number' & isFinite(value)) {
return value;
} else {
return value = 0;
}
}
let arrayFirst = toInt(first.split('').reverse());
let arraySecond = toInt(second.split('').reverse());
let lengthFirst = first.length;let lengthSecond =second.length;
let lengthResult = lengthFirst + lengthSecond - 1;
let result = '';let sum = 0;let olderFigure = 0;
for (let i = 0; i < lengthResult; i++) {
for (let j = 0; j <= i; j++) {
if (((i - j) < second.length) & (j < first.length)) {
sum += crutch(arrayFirst[j] * arraySecond[i - j]);
} else {
sum += 0;
}
}
sum += olderFigure;
olderFigure = Math.floor(sum / 10);
result = sum%10 + result;
sum=0;
}
if(olderFigure>0){
result = olderFigure + result;
}
while(result.startsWith('0')&&result.length>1){
result=result.substring(1);
}
return result;
}