/** * Insertion sort algorithm: https://en.wikipedia.org/wiki/Insertion_sort */ const insertionSort = (list) => { const items = [].concat(list); // lets create a copy, so we don't mutate the original list reference
/** * Binary search algorithm: https://en.wikipedia.org/wiki/Binary_search_algorithm * Will return the index of the 'searchValue' or -1 if not found. */ const binarySearch = (searchValue, array) => {
/** * Generate a human readable slug. */ const VERBS = ['ask', 'build', 'buy', 'drink', 'run', 'toss']; const COLORS = ['blue', 'green', 'orange', 'pink', 'red', 'red'];
/** * Problem: * Given a binary tree, return the postorder traversal of its nodes' values. * * Example:
/** * Given a binary tree, find its minimum depth. * The minimum depth is the number of nodes along the * shortest path from the root node down to the nearest * leaf node.