javascript - Fill array with reverse and forward of own elements -


i trying fill array 'n' values using existing 4 values. want fill sort of pattern goes reverse , forward until reaches capacity of 'n' values.

for example, array:

var array = [a, b, c, d]; 

i want resulting array follow pattern:

array = [a, b, c, d,          c, b, a, b,           c, d, c, b,          a, b, c, d...(continues pattern)] 

concat(), slice(), , reverse() going.

this repeats pattern 100 times:

var array = ['a', 'b', 'c', 'd'];    for(var = 0 ; < 100 ; i++) {    array = array.concat(array.slice(0,3).reverse());    array = array.concat(array.slice(1,4));  }    document.body.innerhtml= array.join(' ');


Comments