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
console.log("hello 2"); | |
process.stdin.resume();//standard in starts paused by default, resume it to be able to get data | |
process.stdin.on("data", function(d) {//we got some data | |
console.log("hello 2 received data:"); | |
console.log(d+"");//turn it into a string before logging it to standard out | |
}); | |
/* |
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
console.log("hello 1"); | |
/* | |
try running | |
$ node hello1.js | |
logs out "hello 1" and exits | |
*/ |
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
// A 0+ integer of unlimited size | |
function Int(p) { // Takes a number like 5, a string of numerals like "789", a bignumber.js BigNumber, or another Int | |
if (isType(p, "Int")) return p; // Return the given Int instead of making a new one, the value inside an Int can't change | |
var o = {}; | |
o.v = _3type(p); // Parse the given parameter, keeping together v.s() numerals, and v.n() number and v.b() BigNumber once we have them or they are necessary | |
o.inside = o.v.inside; // Point to function, see which types v has built up with text like "bns" or "--s" for testing | |
o.add = function(q) { return _add(o.v, q); } // Math | |
o.subtract = function(q) { return _sub(o.v, q); } | |
o.multiply = function(q) { return _mul(o.v, q); } |
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
// A 0+ integer of unlimited size | |
function Int(p) { // Takes a number like 5, a string of numerals like "789", a bignumber.js BigNumber, or another Int | |
if (isType(p, "Int")) return p; // Return the given Int instead of making a new one, the value inside an Int can't change | |
var o = {}; | |
o.v = _3type(p); // Parse the given parameter, keeping together v.s numerals, and v.n number and v.b BigNumber once we have them or they are necessary | |
o._ = function(c, q) { return _calculate(o.v, c, _3type(q)); } // Who says JavaScript can't do operator overloading? | |
o.text = o.v.s(); | |
o.hasNumber = function() { return o.v.fit; } // True if our value is small enough it will fit in a number as an integer, not a floating point number | |
o.toNumber = function() { return o.v.n(); } // Throws if too big | |
o.type = "Int"; |
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
var color1 = "red"; | |
function set2() { | |
this["color2"] = "orange"; | |
} | |
function set3(destination) { | |
destination["color3"] = "yellow"; | |
} |
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
var color1 = "red"; | |
function set2() { | |
this["color2"] = "orange"; | |
} | |
function set3(destination) { | |
destination["color3"] = "yellow"; | |
} |
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
//make something available to the file from within a function in the file | |
//make sure it doesn't affect what's available in files that require this one | |
var color1 = "red"; | |
var color2 = "orange"; | |
//and we want to set two more colors, using the function below | |
function setColors() { |
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
//make something available to the file from within a function in the file | |
//make sure it doesn't affect what's available in files that require this one | |
var color1 = "red"; | |
var color2 = "orange"; | |
//and we want to set two more colors, using the function below | |
function setColors() { | |
var extraColors = {color3:"yellow", color4:"green"}; |
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
//any type, variable value | |
*a = 7; //make a new variable and set it to 7 | |
a = "hello"; //its a var, so we can set it to something of a different type | |
//one type, variable value | |
Text b; | |
b = "some text"; | |
b = 7; //throws | |
//any type, permanent value |
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
function _number(s, base) { | |
if (typeof s !== "string") throw "type"; | |
var n = parseInt(s, base); | |
if (isNaN(n)) throw "data"; | |
if (!match(_numerals(n, base), s)) throw "data"; // Guard against parseInt's dangerously accommodating parsing style by ensuring that the number we made becomes the same text we made it from | |
return n; | |
} |