Trying to write a javascript function that counts to the number inputted -
trying take integer , have return a
string integers 1 number passed. trying use loop return string not sure how!
example of how want look:
count(5) => 1, 2, 3, 4, 5 count(3) => 1, 2, 3
not sure start
i recursive function. keep concatenating numbers until reaches 1.
var sequence = function(num){ if(num === 1) return '1'; return sequence(num - 1) + ', ' + num; }
or just:
var sequence = (num) => num === 1 ? '1' : sequence(num - 1) + ', ' + num;
Comments
Post a Comment