Skip to content

Instantly share code, notes, and snippets.

@brianloveswords
Created February 27, 2016 00:01
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 brianloveswords/4103b324528f0464174b to your computer and use it in GitHub Desktop.
Save brianloveswords/4103b324528f0464174b to your computer and use it in GitHub Desktop.
/// <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