Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Scott Lewis iconifyit

🏠
Working from home
View GitHub Profile
@iconifyit
iconifyit / CEP-fixVolumePathBug.jsx
Created Sep 1, 2020
Fixes a bug in Adobe CEP where CEP confuses connected drives with local folders when the relative paths are the same. For instance "/Volumes/Users/username" and "/Users/username"
View CEP-fixVolumePathBug.jsx
/**
* Bug fix for the issue described at the link below.
* @link https://community.adobe.com/t5/indesign/extendscript-oddity-with-file-folder-on-mac-os-x/m-p/3887816?page=1#M165105
*/
function fixVolumePathBug(filepath) {
if ($.os.toLowerCase().indexOf('mac') === -1) return filepath;
var $HOME = new Folder('~/').fsName;
if (filepath.indexOf($HOME) > 0) {
@iconifyit
iconifyit / 08-binary-search.js
Last active Feb 26, 2020
30 Days of Algorithms : Day 08 - Binary Search
View 08-binary-search.js
/*
* Iterative search.
* Big-O = O(logN)
*/
const binarySearch = (haystack, needle) => {
let start = 0,
end = haystack.length - 1;
/*
@iconifyit
iconifyit / quick-sort.js
Last active Feb 24, 2020
30 Days of Algorithms : 07 - Quick Sort
View quick-sort.js
/**
* Partitions array into halves.
* O(log n) Big-O notation
* @param items
* @param left
* @param right
* @returns {*}
*/
const partition = (items, left, right) => {
@iconifyit
iconifyit / 06-merge-sort.js
Created Feb 19, 2020
30 Days of Algorithms - Day 06 Merge Sort
View 06-merge-sort.js
/**
* Recursively split, sort, and re-merge the array.
* @param unsortedArray
* @returns {*[]|*}
*
* Big-O:
*
* Space complexity : O(n)
* Time complexity : O(n Log n)
*/
@iconifyit
iconifyit / 05-array-to-tree.js
Created Feb 17, 2020
30 Days of Algorithms : Day 05 - Create a tree from a flat array.
View 05-array-to-tree.js
/**
* Converts a flat array to a tree with runtime O(n)
*
* Big-O : O(n)
*
* This algorithm was taken from Phillip Stanislaus's "Performant Array to Tree"
* which has O(n) complexity. It builds the tree in a single pass.
* @link https://github.com/philipstanislaus
* @link https://www.npmjs.com/package/performant-array-to-tree
* @see https://github.com/iconifyit/30-Days-of-Algorithms
@iconifyit
iconifyit / bubble-sort.js
Created Feb 17, 2020
30 Days of Algorithms - Day 03 : Bubble Sort
View bubble-sort.js
/**
* 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
@iconifyit
iconifyit / 04-shared-list-items.js
Last active Mar 5, 2020
30 Days of Algorithms : 04 - Find shared items between two lists.
View 04-shared-list-items.js
/**
* Find shared elements between two lists.
* @param {array} x
* @param {array} y
* @returns {[]}
*/
const shared_items = ( x, y ) => {
x.sort();
y.sort();
@iconifyit
iconifyit / find-missing-number-1-n.js
Last active Feb 15, 2020
30 Days of Algorithms : Find the missing number in an array of numbers 0 ... N
View find-missing-number-1-n.js
/**
* 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
@iconifyit
iconifyit / GreatestCommonDivisor.js
Last active Feb 15, 2020
30 Days of Algorithms : Euclid's Algorithm to find Greatest Common Divisor
View GreatestCommonDivisor.js
/**
* 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
@iconifyit
iconifyit / valid-number.js
Created Jan 31, 2020
Solution to "Is it a valid number coding test". See the first comment below for test cases.
View valid-number.js
/**
* The main function.
* @param s
* @returns {boolean}
*/
function isNumber(s) {
s = s.trim();
var chars = new Set(s);
You can’t perform that action at this time.