Skip to content

Instantly share code, notes, and snippets.

@zolotyh
Created March 24, 2020 21:34
Show Gist options
  • Save zolotyh/49f76d143b6d1a41832b82fd9edc85fc to your computer and use it in GitHub Desktop.
Save zolotyh/49f76d143b6d1a41832b82fd9edc85fc to your computer and use it in GitHub Desktop.
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