╰ゝ天使的微笑

文章 评论 浏览 25

╰ゝ天使的微笑 2022-05-04 13:56:27
function method(arr) {
  arr = Array.from(new Set(arr.sort((a, b) => a - b)))
  const result = []
  const len = arr[arr.length - 1] / 10 + 1
  let current = 0
  for (let i = 1; i <= len; i++) {
    console.log(i)
    let min = (i - 1) * 10
    let max = 10 * i
    const temp = []
    for (let j = current; j < arr.length; j++) {
      if (arr[j] >= min && arr[j] < max) {
        temp.push(arr[j])
        if (j === arr.length - 1) {
          result.push(temp)
        }
      } else {
        if (temp.length > 0) {
          current = j
          result.push(temp)
        }
        break
      }
    }
  }
  return result
}
function randomMethod() {
  const arr = []
  arr.length = 10
  for (let i = 0; i < arr.length; i++) {
    arr[i] = Math.floor(Math.random() * 100)
  }
  return arr
}
console.log(method(randomMethod()))

第 67 题:随机生成一个长度为 10 的整数类型的数组

╰ゝ天使的微笑 2022-05-04 13:26:37

//题目开放,变式很多了
const dateTransfer = (start, end) => {
const distance = 1000 * 60 * 60 * 24;
const startTime = new Date(start).getTime();
const endTime = new Date(end).getTime();
const result = [];

while(startTime < endTime){
    result.push(new Date(startTime + distance).toLocaleDateString().replace(///g, '-'));
    startTime +=  distance;   
}
return result;

}

dateTransfer('2019-08-01', '2019-08-30')

第 134 题:求两个日期中间的有效日期

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文