Skip to content

Instantly share code, notes, and snippets.

View zootella's full-sized avatar
🏔️

Kevin Faaborg zootella

🏔️
View GitHub Profile
//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"};
//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 color1 = "red";
function set2() {
this["color2"] = "orange";
}
function set3(destination) {
destination["color3"] = "yellow";
}
var color1 = "red";
function set2() {
this["color2"] = "orange";
}
function set3(destination) {
destination["color3"] = "yellow";
}
// 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";
// 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); }
var makePerson = function (name, age) {
var me = {}, my = {};
//members
my.name = name;
my.age = age;
//private methods
// 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
var newFile = function() {
var state = newState();
function close() {//maybe state.close = function() instead
if (state.already()) { log('already closed'); return; }
};
state.pulse = function() {
// ----
var start = new Date();
// ----
var size = 10000;
var a = [];
for (var i = 0; i < size; i++) {
a.push(i);