Created
September 17, 2017 00:32
-
-
Save OverlappingElvis/f9573faf28405c5d491161f22bbf377c to your computer and use it in GitHub Desktop.
I'se A Muggin' (Part 2)
This file contains hidden or 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
/* | |
I really wanted my band to do this Mezz Mezzrow song (https://www.youtube.com/watch?v=UEQ6v0pWUcg) but nobody wanted to learn the sequence. Now they have no excuse. | |
*/ | |
var _ = require('underscore'); | |
// Folks, we're gonna do some muggin' with numbers. "Well explain it to me, man!" | |
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)); | |
}; | |
// "Alright boys, here we go!" | |
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(); | |
// "But Jeremy! You should have had that last reduce put out an array of arrays so you could do this all in the Underscore chain!" | |
// Yup. But I wrote this while waiting in line for the 3D printer at the library, and I'm probably not going to change it now. Unless I do. | |
var lines = _(lyrics.split('\n')).reduce(function(song, line, index) { | |
// Maybe the first line should actually be broken up, but I think it's fine to leave as is | |
if (index === 0 || index % 2 === 0) { | |
return song + line + '\n'; | |
} | |
return song + line + '\t'; | |
}, ''); | |
// *Clears throat, does best Mezz Mezzrow impression* | |
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
I think coding interviews should use MezzMezzrow instead of FizzBuzz