Skip to content

Instantly share code, notes, and snippets.

@jiggzson
jiggzson / scientificToDecimal.js
Last active August 22, 2024 05:03
Converts a javascript number from scientific notation to a decimal string
/**
* Removes the minus sign from the beginning of the string
*
* @param str
* @returns an array with the first item as true if a minus
* was found and the string minus the minus sign.
*/
function stripSign(str) {
// Check if it has a minus sign
let hasMinus = str.charAt(0) === '-';
var Fraction = {
convert: function( value, opts ) {
var frac;
if( value === 0 ) {
frac = [ 0, 1];
}
else {
if( value < 1e-6 || value > 1e20) {
var qc = this.quickConversion( Number( value ) );
if( qc[1] <= 1e20 ) {
@jiggzson
jiggzson / getBetweenBrackets.js
Last active August 29, 2015 14:08
Gets between two provided brackets
/**
* This method gets between a bracket and returns what's between the brackets only
* after it's been balanced. This can be done with a regex however is microsecond
* optimizations aren't too important then this becomes a more versatile solution which
* can accept a multitude of brackets and braces.
* @param {String} ob The opening bracket or brace
* @param {String} cb The closing bracket or brace
* @param {String} str The string containing the brackets
* @param {Integer} start The starting index from where to start searching
* @example getBetweenBrackets('(',')', 'all_of_this(but((I_want_this)))')