This file contains hidden or 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 round = function (value) { | |
// {value is some number} | |
var multiplier = Math.abs(value) / value; | |
var sValue = (value + (0.5 * multiplier)).toString(); | |
var point = sValue.indexOf("."); | |
return parseInt(sValue.substring(0, point === -1 ? sValue.length : point), 10); | |
// {returns value rounded} | |
}; |
This file contains hidden or 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 divide = function (numerator, denominator) { | |
return numerator * (1 / denominator); | |
}; |
This file contains hidden or 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
import java.io.*; | |
import java.util.*; | |
public class FilterTextFile { | |
public static void main(String[] args) throws FileNotFoundException { | |
Scanner fScan, cScan = new Scanner(System.in); | |
String inFile, outFile, findStr; | |
FileInputStream fileInput; | |
PrintWriter fileOutput; | |
This file contains hidden or 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 reverseNumber = function (maxValue, value) { | |
return (maxValue - 1) - value; | |
}; | |
var hex2Dec = function (hexStr) { | |
return parseInt(hexStr, 16); | |
}; | |
var dec2Hex = function (decStr, digits) { | |
var hexStr = decStr.toString(16); | |
var chars = digits - hexStr.length; | |
var count; |
This file contains hidden or 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 bubbleSort = function (list) { | |
var i, temp; | |
var swapped = true; | |
var iterations = 0; | |
var n = list.length; | |
while (swapped) { | |
swapped = false; | |
for (i = 1; i < n; i += 1) { | |
iterations += 1; |
This file contains hidden or 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
// Using func. https://gist.github.com/ryansmith94/5564105 | |
func("toArray", function (elemDelimeter, attrDelimeter, fn) { | |
var i, elemArray, len; | |
elemArray = this.split(elemDelimeter); | |
len = elemArray.length; | |
for (i = 0; i < len; i += 1) { | |
elemArray[i] = elemArray[i].split(attrDelimeter); | |
if (fn) { |
This file contains hidden or 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
// Using func. https://gist.github.com/ryansmith94/5564105 | |
func("replaceAll", function (x, y) { | |
var self = this; | |
while (self.indexOf(x) !== -1) { | |
self = self.replace(x, y); | |
} | |
return self; | |
}, String.prototype); |
This file contains hidden or 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
// Using func. https://gist.github.com/ryansmith94/5564105 | |
func("toObject", function (keys, values) { | |
var i; | |
var len = keys.length; | |
var result = {}; | |
values = values || this; | |
for (i = 0; i < len; i += 1) { | |
result[keys[i]] = values[i]; |
This file contains hidden or 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
// new Function. | |
var x = (new Function("return " + data))(); | |
// (1) Better than using eval. | |
var x = eval("(" + data + ")"); |
This file contains hidden or 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 function to create non-enumerable functions in specific scopes. | |
var func = (function (defineProp, undefined) { | |
"use strict"; | |
// In older browsers Object.defineProperty is not available. | |
// In IE8 Object.defineProperty can only be used on DOM elements. | |
var initProp = (!defineProp || !defineProp({}, "ie8Test", {value: false})) ? | |
function () {} : | |
function (name, scope, write, enumer, config) { | |
enumer = (enumer === undefined ? false : enumer); |