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
//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; | |
} |
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 start = new Date(); | |
// ---- | |
var size = 10000; | |
var a = []; | |
for (var i = 0; i < size; i++) { | |
a.push(i); |
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 newFile = function() { | |
var state = newState(); | |
function close() {//maybe state.close = function() instead | |
if (state.already()) { log('already closed'); return; } | |
}; | |
state.pulse = function() { |
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
// Calculate the average of a number of values as they are produced | |
var newAverage = function() { | |
var o = {}; | |
var n = 0; o.n = function() { return n; } // How many values we have, 0 before you add one | |
var total = 0; o.total = function() { return total; } // The total sum of all the given values | |
var minimum = 0; o.minimum = function() { return minimum; } // The smallest value we have seen, 0 before we have any values | |
var maximum = 0; o.maximum = function() { return maximum; } // The largest value we have seen, 0 before we have any values | |
var recent = 0; o.recent = function() { return recent; } // The most recent value you added, 0 before we have any values |
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 makePerson = function (name, age) { | |
var me = {}, my = {}; | |
//members | |
my.name = name; | |
my.age = age; | |
//private methods |
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"; |