Created
March 24, 2020 21:34
-
-
Save zolotyh/49f76d143b6d1a41832b82fd9edc85fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* range(start, end) { | |
for (let i = start; i <= end; i++) { | |
yield i; | |
} | |
} | |
function getNoun(number, one, two, five) { | |
let n = Math.abs(number); | |
n %= 100; | |
if (n >= 5 && n <= 20) { | |
return five; | |
} | |
n %= 10; | |
if (n === 1) { | |
return one; | |
} | |
if (n >= 2 && n <= 4) { | |
return two; | |
} | |
return five; | |
} | |
for (i of range(0, 200)) { | |
const noun = getNoun(i, 'неделя', 'недели', 'недель') | |
console.log(`${i} ${noun}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment