javascript - How to print array repeatedly with a specified number of times -


i have array example:

var arr = ['a','b','c','d'];

now ask user insert number example: 6 or 7 or 10 or number.

lets take example user has enter: 10

now output should be: b c d b c d b

total of 10 values should print using array values in order.

but main problem there should no if condition

you need make use of modulus operator (%). docs here

pseudo code:

loop index     output yourarray[i % yourarray.length] end loop 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -