-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFizzBuzzWithArray.js
More file actions
33 lines (25 loc) · 993 Bytes
/
FizzBuzzWithArray.js
File metadata and controls
33 lines (25 loc) · 993 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
const fizzbuzz = (counter,printvalus,msg = '') => {
let i = 0;
//Recursive function to check divisiblity of each member of array
const arrDivision = (counter,printvalus,i,msg='') => {
if (i === printvalus.length)
return msg;
if(printvalus[i])
{
if (counter % (i+1) === 0)
{
msg += counter + ':' + printvalus[i] + '\n'
}
}
return arrDivision(counter,printvalus,i+1,msg) // Recursion on array
}
if (counter === 0)
return msg;
else
{
msg += arrDivision(counter,printvalus,i)
}
return fizzbuzz(counter-1,printvalus,msg) // Recursion on Counter
}
const printvalus = [undefined, undefined, 'Fizz', undefined, 'Buzz' ,undefined, undefined, 'wot']
console.log(fizzbuzz(100,printvalus))