当前位置:网站首页>Output 0 ~ n digits and output multiple times

Output 0 ~ n digits and output multiple times

2022-06-25 14:18:00 jason_ renyu

Output 0~n And output it many times , This method is similar to the output 010101010101,012012012012012,012301230123, Such a sequence of numbers ;
In this way, the output sequence can make an array output several times in sequence , It is not clear what this method is called , Or it is not an algorithm , Put it here first. If you know, please leave a message below , thank you !

javascript The way


const sFun = (value, length, vflag) => {
    
  let n = value;
  //  Judge whether the critical value is reached 
  //  Default as value = 6, The returned number is  0-5  Six bit loop 
  if (vflag) {
    
    n = value + 1;
  }
  let l = length + 1;
  let page = 1;
  let arr = [];
  for (let i = 1; i < l; i++) {
    
    let resultN = n + (i - page * n - 1);
    arr.push(resultN)
    if (i % n == 0) {
    
      page++
    }
  }
  return arr;
}

console.log(sFun(6, 100, true))

Java The method is followed by …

原网站

版权声明
本文为[jason_ renyu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200522173811.html