Given a month as an integer from 1 to 12, return to which quarter of the year it belongs as an integer number.

For example: month 2 (February), is part of the first quarter; month 6 (June), is part of the second quarter; and month 11 (November), is part of the fourth quarter.

void main() { test("Basic Tests", () { expect(quarter(3), 1); expect(quarter(8), 3); expect(quarter(11), 4); }); }

내답:

int quarter(int month) { if (month <= 3) { return 1; } else if (month <= 6 && month > 3){ return 2; } else if (month <= 9 && month > 6){ return 3; } else { return 4; } }

int quarter(int month) {
  return (month + 2) ~/ 3;
}

~/ 는 나누는 몱

int quarter(int month) => (month / 3).ceil();