Is there any good algorithm for repeating output from small to big, and then from big to small?

topic description

how to loop the output in positive order and then in reverse order,
for example: 123321123321

sources of topics and their own ideas

the idea is to give an array to 3 and reverse it

.

related codes

arr=[3,2,1]

for(i=0;i<18;iPP){
  if(i%3==0){
    arr.reverse()
  }
  console.log(arr[i%3])
}

what result do you expect? What is the error message actually seen?

the above code looks perfect, but why ask questions, because a function is needed in the specific application

y=func (x)

Xerox 1
Xerox 2
Xerox 3
3
4
5
6
such an infinite cycle, I can"t write any more, please ask everyone for help

, please do not know how to write, please ask for help if you can"t write any more, please ask everyone for help

Aug.25,2021

it seems that all junior high school math has been lost.

for(var i=1;i<=18;iPP){
  console.log(func(i,3))
}

function func(num,n){
  var d = Math.ceil(num/n)-1
  
  return Math.abs(((num-n*d)-(n+1)*(d%2)))
}

https://jsbin.com/tomaxujiza/.


didn't pay attention to the examination, revise it. Originally, it was a good way to change it to this way.
generally, this kind of operation is recommended to be implemented with generator. The method of not taking the remainder is to avoid unpredictable problems caused by too large numbers in the later stage

.
function* gen(arr) {
    let array = arr.concat(arr.reverse())
    for  (let x=1;true;xPP) {
        for (let j=0;j<array.length;jPP){
            yield {x:x,y:array[j]}
        }
    }
}

generator = gen([1,2,3])
for (let _=0;true;_PP){
    console.log(generator.next().value)
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36777-4ec7e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36777-4ec7e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?