Created
February 27, 2016 00:01
-
-
Save brianloveswords/4103b324528f0464174b to your computer and use it in GitHub Desktop.
This file contains 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
/// <reference path="node.d.ts" /> | |
"use strict"; | |
const HEARTS: Array<string> = | |
["β€","β₯","π","π","π","π","π","π","π","π","π","π","π",]; | |
const BIRTHDAY: Array<string> = ["π","π","π°","π","π","π","π"]; | |
const EMOJI = BIRTHDAY; | |
function randomItem(array: Array<string>): string { | |
const index = Math.random() * array.length | 0; | |
return array[index]; | |
} | |
function *emojiGenerator(): Iterator<string> { | |
while (true) { | |
yield randomItem(EMOJI); | |
} | |
} | |
function take<T>(generator: Iterator<T>, count: number): GeneratorFunction { | |
return function* () { | |
while (count--) { yield generator.next(); } | |
}; | |
} | |
(function main(): void { | |
const numberOfElements: number = parseInt(process.argv[2]) || 140; | |
const printEmoji = take(emojiGenerator(), numberOfElements); | |
for (let emoji of printEmoji()) { | |
process.stdout.write(emoji.value); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment