Skip to content

Instantly share code, notes, and snippets.

@aguestuser
Created November 2, 2015 19:29
Show Gist options
  • Save aguestuser/b2eda1bfb5796b1e76d1 to your computer and use it in GitHub Desktop.
Save aguestuser/b2eda1bfb5796b1e76d1 to your computer and use it in GitHub Desktop.
scratchpad: example mini-program for learning about node & bash
// main loop
// run with `node scratchpad some arguments` (from same directory)
(function (){
var args = process.argv;
console.log(wrapInEverything(args[2]));
// teaser for later: what will lines 11-13 do?
// what about lines 15-17?
// for(var i; i < args.length; i++){
// console.log(wrapInSmileys(args[i]));
// }
// args.forEach(function(arg){
// console.log(wrapInSadFace(arg));
// });
})(); // <- self-invoking function!
// helper functions
function wrapInEverything(string){
return wrapInSmileys(wrapInSadFace(string));
}
function wrapInSmileys(string){
return ":) " + string + " :)";
}
function wrapInSadFace(string){
return ":( " + string + " :(";
}
// GUESS AT HOW call to `wrapInEnverything` might evaluate...
// "wrapInEverything('wrapme')"
// ":)" "wrapme" ":)"
//":) wrapme :)"
// ":(" ":) wrapme :)" ":("
// ":( :) wrapme :) :(" ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment