Skip to content

Instantly share code, notes, and snippets.

Created September 16, 2017 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/0763085609e1d2561c17ebce6026b329 to your computer and use it in GitHub Desktop.
Save anonymous/0763085609e1d2561c17ebce6026b329 to your computer and use it in GitHub Desktop.
I'se A Muggin (Pt. 2)
var _ = require('underscore');
var lessThanSeventy = function(number) {
if (number === 7) {
return 'uh';
}
if (number === 10) {
return 'woof';
}
if (number % 7 === 0 || number.toString().indexOf('7') !== -1) {
return 'uh uh';
}
if (number % 10 === 0) {
return 'woof woof'
}
return number;
};
var greaterThanSeventy = function(number) {
var split = number.toString().split('');
return 'uh ' + lessThanSeventy(parseInt(split[1], 10));
};
var lyrics = _(_.range(1, 81)).chain()
.map(function(number) {
if (number === 80) {
return 'woof woof';
}
return number > 70 ? greaterThanSeventy(number) : lessThanSeventy(number);
})
.reduce(function(song, number, index) {
var joined = song + number;
if (index < 4) {
return joined + (index === 3 ? '\n' : ', ');
}
if (index < 12) {
return joined + (index % 2 !== 0 ? '\n' : ', ');
}
return joined + '\n';
}, '')
.value();
var lines = _(lyrics.split('\n')).reduce(function(song, line, index) {
if (index === 0 || index % 2 === 0) {
return song + line + '\n';
}
return song + line + '\t';
}, '');
console.log(lines);
/*
1, 2, 3, 4
5, 6 uh, 8
9, woof 11, 12
13 uh uh
15 16
uh uh 18
19 woof woof
uh uh 22
23 24
25 26
uh uh uh uh
29 woof woof
31 32
33 34
uh uh 36
uh uh 38
39 woof woof
41 uh uh
43 44
45 46
uh uh 48
uh uh woof woof
51 52
53 54
55 uh uh
uh uh 58
59 woof woof
61 62
uh uh 64
65 66
uh uh 68
69 uh uh
uh 1 uh 2
uh 3 uh 4
uh 5 uh 6
uh uh uh 8
uh 9 woof woof
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment