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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -