js求连个数之间的数字

整理出自项目中一个需求,求两个数之间的数字。

const week = function(arr,arr2){
        let a=parseInt(arr);
      let b=parseInt(arr2);
      let c = [];
      if (arr - b < 0) {
        const number = Math.abs(a - b) + 1;
        for (let i = a; i < a + number; i++) {
          c.push(i);
        }
      } else if (a - b === 0) {
        c.push(a)
      } else if (a - b > 0) {
        const number = Math.abs(a - b);
        for (let i = a; i > number; i--) {
          c.push(i);
        }
      }
      return c.join(',');
    }
    console.log(week(1,15))

  

猜你喜欢

转载自www.cnblogs.com/webSong/p/9316395.html