Help us understand the problem. What is going on with this article?

【JavaScript】半年間の月を取得する

More than 1 year has passed since last update.

今月が12月だったら

[7, 8, 9, 10, 11, 12]

こんな感じで取得したい。

1月やったら、

[8, 9, 10, 11, 12, 1]

こんな感じ

自分が実装したコード

sample.js
export function getHalfYear() {
  const HALF_YEAR = 6
  const TWELVE_MONTH = 12
  var halfYear = []
  var now = new Date()
  var month = now.getMonth() + 1
  for (var i = 0; i < HALF_YEAR; i++) {
    if (month - i <= 0) {
      halfYear.push(month - i + TWELVE_MONTH)
    } else {
      halfYear.push(month - i)
    }
  }
  return halfYear.reverse()
}

レビュー頂けると、嬉しいです!

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away