Skip to content

Instantly share code, notes, and snippets.

@hperrin
Last active May 20, 2020 05:22
Show Gist options
  • Select an option

  • Save hperrin/d86131552154ab0bb4ba2c85edad93d7 to your computer and use it in GitHub Desktop.

Select an option

Save hperrin/d86131552154ab0bb4ba2c85edad93d7 to your computer and use it in GitHub Desktop.

Revisions

  1. hperrin revised this gist May 20, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions 99bottlesofbeer.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    function verses(bottles) {
    const count = (b, cap) => `${b || `${cap ? 'N' : 'n'}o more`} bottle${b == 1 ? '' : 's'}`;

    return [...new Array(bottles + 1)].map((v, i) => bottles - i).map(b => ([
    return [...new Array(bottles + 1)].map((v, i) => bottles - i).map(b => [
    `${count(b, true)} of beer on the wall, ${count(b)} of beer.`,
    b > 0
    ? `Take one down and pass it around, ${count(b - 1)} of beer on the wall.`
    : `Go to the store and buy some more, ${count(bottles)} of beer on the wall.`
    ]));
    ]);
    }

    const container = document.createElement('pre');
  2. hperrin revised this gist May 20, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 99bottlesofbeer.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ function verses(bottles) {
    const count = (b, cap) => `${b || `${cap ? 'N' : 'n'}o more`} bottle${b == 1 ? '' : 's'}`;

    return [...new Array(bottles + 1)].map((v, i) => bottles - i).map(b => ([
    `${count(b, true)} of beer on the wall, ${count(b)} of beer!`,
    `${count(b, true)} of beer on the wall, ${count(b)} of beer.`,
    b > 0
    ? `Take one down and pass it around, ${count(b - 1)} of beer on the wall.`
    : `Go to the store and buy some more, ${count(bottles)} of beer on the wall.`
  3. hperrin revised this gist May 20, 2020. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions 99bottlesofbeer.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    function verses(bottles) {
    const bottleString = (b, cap) => `${b || `${cap ? 'N' : 'n'}o more`} bottle${b == 1 ? '' : 's'}`;
    const count = (b, cap) => `${b || `${cap ? 'N' : 'n'}o more`} bottle${b == 1 ? '' : 's'}`;

    return [...new Array(bottles + 1)].map((v, i) => bottles - i).map(b => ([
    `${bottleString(b, true)} of beer on the wall, ${bottleString(b)} of beer!`,
    `${count(b, true)} of beer on the wall, ${count(b)} of beer!`,
    b > 0
    ? `Take one down and pass it around, ${bottleString(b - 1)} of beer on the wall.`
    : `Go to the store and buy some more, ${bottleString(bottles)} of beer on the wall.`
    ? `Take one down and pass it around, ${count(b - 1)} of beer on the wall.`
    : `Go to the store and buy some more, ${count(bottles)} of beer on the wall.`
    ]));
    }

  4. hperrin revised this gist May 20, 2020. 1 changed file with 11 additions and 11 deletions.
    22 changes: 11 additions & 11 deletions 99bottlesofbeer.js
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    function sing(bottles) {
    const count = (b, cap) => `${b || `${cap ? 'N' : 'n'}o more`} bottle${b == 1 ? '' : 's'}`;
    function verses(bottles) {
    const bottleString = (b, cap) => `${b || `${cap ? 'N' : 'n'}o more`} bottle${b == 1 ? '' : 's'}`;

    [...new Array(bottles + 1)].map((v, i) => bottles - i).forEach(b => {
    console.log(`${count(b, true)} of beer on the wall, ${count(b)} of beer!`);
    if (b > 0) {
    console.log(`Take one down and pass it around, ${count(b - 1)} of beer on the wall.`);
    } else {
    console.log(`Go to the store and buy some more, ${count(bottles)} of beer on the wall.`);
    }
    });
    return [...new Array(bottles + 1)].map((v, i) => bottles - i).map(b => ([
    `${bottleString(b, true)} of beer on the wall, ${bottleString(b)} of beer!`,
    b > 0
    ? `Take one down and pass it around, ${bottleString(b - 1)} of beer on the wall.`
    : `Go to the store and buy some more, ${bottleString(bottles)} of beer on the wall.`
    ]));
    }

    sing(99);
    const container = document.createElement('pre');
    container.innerText = verses(99).map(verse => verse.join('\n')).join('\n\n');
    document.body.appendChild(container);
  5. hperrin revised this gist May 20, 2020. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions 99bottlesofbeer.js
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,13 @@
    function sing(bottles) {
    const bottleString = (b, cap) => `${b || `${cap ? 'N' : 'n'}o more`} bottle${b == 1 ? '' : 's'}`;
    const count = (b, cap) => `${b || `${cap ? 'N' : 'n'}o more`} bottle${b == 1 ? '' : 's'}`;

    [...new Array(bottles + 1)].map((v, i) => bottles - i).forEach(b => {
    console.log(`${bottleString(b, true)} of beer on the wall, ${bottleString(b)} of beer!`);
    if (b > 0) {
    console.log(`Take one down and pass it around, ${bottleString(b - 1)} of beer on the wall.`);
    [...new Array(bottles + 1)].map((v, i) => bottles - i).forEach(b => {
    console.log(`${count(b, true)} of beer on the wall, ${count(b)} of beer!`);
    if (b > 0) {
    console.log(`Take one down and pass it around, ${count(b - 1)} of beer on the wall.`);
    } else {
    console.log(`Go to the store and buy some more, ${bottleString(bottles)} of beer on the wall.`)
    }
    console.log(`Go to the store and buy some more, ${count(bottles)} of beer on the wall.`);
    }
    });
    }

  6. hperrin revised this gist May 20, 2020. 1 changed file with 8 additions and 6 deletions.
    14 changes: 8 additions & 6 deletions 99bottlesofbeer.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,13 @@
    function sing(bottles) {
    [...new Array(bottles + 1)].map((v, i) => bottles - i).forEach(b => {
    console.log(`${b} bottle${b == 1 ? '' : 's'} of beer on the wall, ${b} bottle${b == 1 ? '' : 's'} of beer!`);
    if (b > 0) {
    console.log(`Take one down and pass it around, ${b - 1} bottle${b - 1 == 1 ? '' : 's'} of beer on the wall.`);
    const bottleString = (b, cap) => `${b || `${cap ? 'N' : 'n'}o more`} bottle${b == 1 ? '' : 's'}`;

    [...new Array(bottles + 1)].map((v, i) => bottles - i).forEach(b => {
    console.log(`${bottleString(b, true)} of beer on the wall, ${bottleString(b)} of beer!`);
    if (b > 0) {
    console.log(`Take one down and pass it around, ${bottleString(b - 1)} of beer on the wall.`);
    } else {
    console.log(`Go to the store and buy some more, ${bottles} bottle${bottles == 1 ? '' : 's'} of beer on the wall.`)
    }
    console.log(`Go to the store and buy some more, ${bottleString(bottles)} of beer on the wall.`)
    }
    });
    }

  7. hperrin revised this gist May 20, 2020. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions 99bottlesofbeer.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    function sing(bottles) {
    [...new Array(bottles + 1)].map((v, i) => bottles - i).forEach(b => {
    [...new Array(bottles + 1)].map((v, i) => bottles - i).forEach(b => {
    console.log(`${b} bottle${b == 1 ? '' : 's'} of beer on the wall, ${b} bottle${b == 1 ? '' : 's'} of beer!`);
    if (b > 0) {
    console.log(`Take one down and pass it around, ${b - 1} bottle${b - 1 == 1 ? '' : 's'} of beer on the wall.`);
    if (b > 0) {
    console.log(`Take one down and pass it around, ${b - 1} bottle${b - 1 == 1 ? '' : 's'} of beer on the wall.`);
    } else {
    console.log(`Go to the store and buy some more, ${bottles} bottle${bottles == 1 ? '' : 's'} of beer on the wall.`)
    }
    console.log(`Go to the store and buy some more, ${bottles} bottle${bottles == 1 ? '' : 's'} of beer on the wall.`)
    }
    });
    }

  8. hperrin revised this gist May 20, 2020. No changes.
  9. hperrin created this gist May 20, 2020.
    12 changes: 12 additions & 0 deletions 99bottlesofbeer.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    function sing(bottles) {
    [...new Array(bottles + 1)].map((v, i) => bottles - i).forEach(b => {
    console.log(`${b} bottle${b == 1 ? '' : 's'} of beer on the wall, ${b} bottle${b == 1 ? '' : 's'} of beer!`);
    if (b > 0) {
    console.log(`Take one down and pass it around, ${b - 1} bottle${b - 1 == 1 ? '' : 's'} of beer on the wall.`);
    } else {
    console.log(`Go to the store and buy some more, ${bottles} bottle${bottles == 1 ? '' : 's'} of beer on the wall.`)
    }
    });
    }

    sing(99);