good day.
I’ve a problem with a method recursive, this method will print a numbers in the window.
the function given a number n, print following a pattern for example:
n= 16, difference = 5
16 11 6 1 -4 1 6 11 16
n= 10, difference = 5
10 5 0 5 10
The code:
function pattern(number,dif,m=0, nI=0) {
if (m===2) {
return 0;
}
var nI = nI !== 0 ? nI : number;
if (!(m===2)) {
document.write(number+' ')
}
if (number=== 0 || number < 0){
pattern(number+dif, dif, 1,nI)
}
if (m===0) {
pattern(number-dif, dif, 0,nI)
}
if (m===1) {
if (nI == number) {
pattern(false, false, 2,false)
}
pattern(number+dif, dif, 1,nI)
}
}
pattern(10,5)
Basiclly when the number is in ‘n’ again call the function with parameter m = 2, is executed the reurn but it enters in the sum:
if (m===1) {
if (nI == number) {
pattern(false, false, 2,false)
}
>>> pattern(number+dif, dif, 1,nI) <<<<
}