Skip to content

Instantly share code, notes, and snippets.

@dikarel
Last active October 2, 2016 07:10
Show Gist options
  • Save dikarel/043b7a80bf5908db3f2833fdddbd69fa to your computer and use it in GitHub Desktop.
Save dikarel/043b7a80bf5908db3f2833fdddbd69fa to your computer and use it in GitHub Desktop.
Helper classes for HackerRank
# Reads lines from stdin and run specified function
main = (done) ->
lines = []
readline = require 'readline'
readline.createInterface input: process.stdin
.on 'line', (line) -> lines.push line
.on 'close', -> done lines
# Minified one-liner
main=(d)->l=[];require('readline').createInterface(input:process.stdin).on('line',(i)->l.push i).on('close',->d l)
# Example
main (lines) ->
console.log 'My lines are', lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment