Blog

Archive for the Algorithms Category


JavaScript Function to Find the Longest Common Prefix
Posted on July 20, 2015 in Algorithms, JavaScript by Matt Jennings

In a JavaScript array, find the longest common prefix of all array elements.

function longestCommonPrefix(arr){
// sort() method …

Read more


JavaScript Merge Function that Mergers Two Arrays Already Sorted from Lowest to Highest Numbers
Posted on July 15, 2015 in Algorithms, JavaScript by Matt Jennings

// Function merges 2 arrays that are already sort from
// Lowest to highest numbers
function mergeSortedArrays(arr1, arr2) {

Read more


JavaScript Insertion Sort Algorithm
Posted on July 14, 2015 in Algorithms, JavaScript by Matt Jennings

See this Wikipedia entry for the insertion sort algorithm. This animated GIF from that entry explains more …

Read more


JavaScript Bubble Sort Functions Using a Do/While Loop and Nested For Loops
Posted on July 13, 2015 in Algorithms, JavaScript by Matt Jennings

Per this video, a Bubble Sort is where an array is looped through and the largest …

Read more


JavaScript Function that Takes in a String and Outputs an Object Literal that Counts Characters
Posted on June 24, 2015 in Algorithms, JavaScript by Matt Jennings

function countChar(string) {

// Create an empty object
var countCharObj = {};

// …

Read more