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
if (!String.prototype.startsWith) { | |
Object.defineProperty(String.prototype, 'startsWith', { | |
value: function(search, rawPos) { | |
var pos = rawPos > 0 ? rawPos|0 : 0; | |
return this.substring(pos, pos + search.length) === search; | |
} | |
}); | |
} | |
function MLParser() { |
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
/* | |
https://sciencenotes.org/projectile-motion-example-problem-physics-homework-help/ | |
A cannon is fired with muzzle velocity of 150 m/s at an angle of elevation = 45°. Gravity = 9.8 m/s2. | |
a) What is the maximum height the projectile reaches? | |
b) What is the total time aloft? | |
c) How far away did the projectile land? (Range) | |
d) Where is the projectile at 10 seconds after firing? | |
*/ | |
var knowns = { | |
v0: 150, // m/s |
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 removeDuplicates = function(arr, condition) { | |
var conditionType = typeof condition; | |
if(conditionType !== 'function' || conditionType === 'undefined') { | |
condition = function(a, b) { | |
return a === b; | |
}; | |
} | |
var seen = []; |
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
/* | |
* Javascript has the toExponential method but this allows you to work with string and therefore any number of digits of your choosing | |
* For example Scientific('464589498449496467924197545625247695464569568959124568489548454'); | |
*/ | |
var isInt = function(n) { | |
return n%1 === 0; | |
} | |
var nround = function (x, s) { | |
if (isInt(x)) { | |
if (x >= Number.MAX_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
/** | |
* Convert a number to base 10 give a base and a number array | |
* @param {int[]} n_array | |
* @param {int} base | |
* @returns {int} | |
*/ | |
var to_base10 = function(n_array, base) { | |
n_array.reverse(); | |
var n = 0; | |
for(var i=0, l=n_array.length; i<l; 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
function sqrt(n) { | |
var xn, d, ld; | |
var c = 0; //counter | |
var done = false; | |
var delta = 1e-17; | |
xn = n/2; | |
var safety = 1000; | |
do { | |
//break if we're not converging | |
if(c > safety) |
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
//TODO: Still depends on Math.sqrt and Math.pow | |
var factorial = function(n) { | |
++n; | |
var r = 1; | |
while(n-->1) | |
r*=n; | |
return r; | |
}; | |
var PI = function(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 factorial = function(n) { | |
if(n === 0) | |
return 1; | |
var f = n; | |
while(n > 1) { | |
f *= --n; | |
} | |
return f; | |
}; |
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 factorial = function(n) { | |
++n; | |
var r = 1; | |
while(n-->1) | |
r*=n; | |
return r; | |
} | |
var calculatePI = function(n) { | |
n = n || 30; |
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 F(d) { | |
if(!(this instanceof F)) | |
return new F(d); | |
if(Array.isArray(d)) | |
this.fraction = d; | |
else | |
this.fraction = this.convert(d); | |
} |
NewerOlder