Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges 99 Shortened Bottles of Beer

JavaScript (Node.js), 228 224 bytes -4 bytes thanks to Hakerh400 (b=n=>`${n} bottle${n-1?'s':''} of beer`,w=' on the wall')=>[...Array(99)].map((_,i)=>`${b(i=99-i)}${w}, ${b(i)}. `+(--i...

posted 3y ago by Moshi‭  ·  edited 3y ago by Moshi‭

Answer
#2: Post edited by user avatar Moshi‭ · 2021-08-06T01:28:25Z (over 3 years ago)
  • # [JavaScript (Node.js)], 228 bytes
  • ```javascript
  • (b=n=>`${n} bottle${n-1?'s':''} of beer`,w=' on the wall')=>Array(99).fill().map((_,i)=>`${b(i=99-i)}${w}, ${b(i)}.
  • `+(--i?`Take one down and pass it around, `:(i=99,`Go to the store and buy some more, `))+b(i)+w+'.').join(`
  • `)
  • ```
  • [Try it online!][TIO-krzm1vcx]
  • [JavaScript (Node.js)]: https://nodejs.org
  • [TIO-krzm1vcx]: https://tio.run/##HY3BisMgFEX3@Yq3KOgjUZhlCrbMan6g@6qNmbE1vqB2pJR8eyaT3eVwOPdufk2@JT8XEWlw66hWblVUJ314xwUslRLcNsXHmWV2ZGwBGsE6l3RXFQOKUH4cVBMCQ3X6TMm8eN@jHH0IHOVkZs6vnce9aLlXfS88Lod3XTrYCS6y0S0Xwp/1xTzc1nQwUI1g4gCzyRl8AZPoGYcO9HFvdPqLoNB@ngslt8v2@YJMk4NpI5uL2P4ftLVlkqG8k49cN43G9UYxU3Ay0DcfOeL6Bw "JavaScript (Node.js) – Try It Online"
  • # [JavaScript (Node.js)], ~~228~~ 224 bytes
  • -4 bytes thanks to Hakerh400
  • ```javascript
  • (b=n=>`${n} bottle${n-1?'s':''} of beer`,w=' on the wall')=>[...Array(99)].map((_,i)=>`${b(i=99-i)}${w}, ${b(i)}.
  • `+(--i?`Take one down and pass it around, `:(i=99,`Go to the store and buy some more, `))+b(i)+w+'.').join`
  • `
  • ```
  • [Try it online!][TIO-krzm1vcx]
  • [JavaScript (Node.js)]: https://nodejs.org
  • [TIO-krzm1vcx]: https://tio.run/##HY3BasQgFEX3@Yq3GFCJCl1mwBm66g90V0o1E9M6Y3xBncow@O1p6u5yOJx7Nb8mXaJbswg42W1WGx1VUCd9eIYKI@bs7T7Fy5kkciSkAs4wWhs1L4oABsg/ForxnjB1@pBSvsZoHnQY2KdczErpF3es9Ubq1DAIx@rhWSqHRliVne6pEO6s383N7kULE5YAJkywmpTAZTAR72HioI@twfUbQsZ2nTJG2@Tx/oCEi4VlJ7vLWP9/0JeeSMLkFV3QXae3C4aE3kqP33SmjG1 "JavaScript (Node.js) – Try It Online"
#1: Initial revision by user avatar Moshi‭ · 2021-08-06T00:30:50Z (over 3 years ago)
# [JavaScript (Node.js)], 228 bytes


```javascript
(b=n=>`${n} bottle${n-1?'s':''} of beer`,w=' on the wall')=>Array(99).fill().map((_,i)=>`${b(i=99-i)}${w}, ${b(i)}.
`+(--i?`Take one down and pass it around, `:(i=99,`Go to the store and buy some more, `))+b(i)+w+'.').join(`

`)
```

[Try it online!][TIO-krzm1vcx]

[JavaScript (Node.js)]: https://nodejs.org
[TIO-krzm1vcx]: https://tio.run/##HY3BisMgFEX3@Yq3KOgjUZhlCrbMan6g@6qNmbE1vqB2pJR8eyaT3eVwOPdufk2@JT8XEWlw66hWblVUJ314xwUslRLcNsXHmWV2ZGwBGsE6l3RXFQOKUH4cVBMCQ3X6TMm8eN@jHH0IHOVkZs6vnce9aLlXfS88Lod3XTrYCS6y0S0Xwp/1xTzc1nQwUI1g4gCzyRl8AZPoGYcO9HFvdPqLoNB@ngslt8v2@YJMk4NpI5uL2P4ftLVlkqG8k49cN43G9UYxU3Ay0DcfOeL6Bw "JavaScript (Node.js) – Try It Online"