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
/** | |
* @author Scott Lewis <scott@atomiclotus.net> | |
* @copyright 2020 Scott Lewis | |
* @version 1.0.0 | |
* @url http://github.com/iconifyit | |
* @url https://atomiclotus.net | |
* | |
* ABOUT: | |
* | |
* This JS class is a wrapper for dialogs created with the Script UI Dialog Builder by Joonas Pääkkö. |
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
/** | |
* The main function. | |
* @param s | |
* @returns {boolean} | |
*/ | |
function isNumber(s) { | |
s = s.trim(); | |
var chars = new Set(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
/** | |
* Euclid's algorithm for Greatest Common Divisor. | |
* @param {int} m | |
* @param {int} n | |
* @returns {string|number} | |
* | |
* Given : 0 < n < m | |
* | |
* 1. Divide m by n. If the remainder is 0, GCD is n. | |
* 2. m <-- n, n <-- r |
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
/** | |
* This algorithm finds a missing number in an array of numbers from 1 - N. | |
* This approach only works if there is one-and-only-one missing number, | |
* and no duplicate numbers. There are other algorithms for those cases | |
* which I will cover on a different day. | |
* | |
* Given : a is a list of positive integers from 1 - N | |
* Given : a contains all unique numbers | |
* Given : a has one-and-only-one missing number | |
* Given : n == a.length |
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
/** | |
* Bubble sort. | |
* @param a | |
* @returns {*} | |
* | |
* Big-O : O(n2) | |
* | |
* From wikipedia: | |
* Bubble sort has a worst-case and average complexity of О(n2), where n is the number of | |
* items being sorted. Most practical sorting algorithms have substantially better worst-case |
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
/** | |
* Recursively split, sort, and re-merge the array. | |
* @param unsortedArray | |
* @returns {*[]|*} | |
* | |
* Big-O: | |
* | |
* Space complexity : O(n) | |
* Time complexity : O(n Log 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
/** | |
* Partitions array into halves. | |
* O(log n) Big-O notation | |
* @param items | |
* @param left | |
* @param right | |
* @returns {*} | |
*/ | |
const partition = (items, left, right) => { |
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
/* | |
* Iterative search. | |
* Big-O = O(logN) | |
*/ | |
const binarySearch = (haystack, needle) => { | |
let start = 0, | |
end = haystack.length - 1; | |
/* |
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
/*-------------------------------------------------------------------------------------------------------------------------*/ | |
/** | |
* Adds JSON library support for engines that do not include it natively. | |
*/ | |
"object"!=typeof JSON&&(JSON={}),function(){"use strict";function f(t){return 10>t?"0"+t:t}function quote(t){ | |
return escapable.lastIndex=0,escapable.test(t)?'"'+t.replace(escapable,function(t){var e=meta[t]; | |
return"string"==typeof e?e:"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+t+'"'} | |
function str(t,e){var n,r,o,f,u,i=gap,p=e[t];switch(p&&"object"==typeof p&&"function"==typeof p.toJSON&&(p=p.toJSON(t)), | |
"function"==typeof rep&&(p=rep.call(e,t,p)),typeof p){case"string":return quote(p);case"number":return isFinite(p)?String(p):"null"; | |
case"boolean":case"null":return String(p);case"object":if(!p)return"null";if(gap+=indent,u=[],"[object Array]"===Object.prototype.toString.apply(p)){ |