Created
November 2, 2015 19:29
-
-
Save aguestuser/b2eda1bfb5796b1e76d1 to your computer and use it in GitHub Desktop.
scratchpad: example mini-program for learning about node & bash
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
// 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