Skip to main content

Blog

Archive for the Algorithms Category


In JavaScript Sort Numbers using the sort() Function
Posted on November 28, 2017 in Algorithms, JavaScript by Matt Jennings

var numbers = [2, 1, 111, 222, 33, -2];

// Output is [-19, -2, 1, 33, 111, 222]
// because the ‘return …

Read more


In JavaScript Show Longest Word in a String
Posted on November 28, 2017 in Algorithms, JavaScript, Regular Expressions by Matt Jennings

function longestWord(sen) {
// ‘sen’ is a string and ‘match’
// matches all the items in the …

Read more


Determine If a Positive Integer is a Prime Number Using JavaScript
Posted on November 27, 2017 in Algorithms, JavaScript by Matt Jennings

function getPrimeNumber(num) {

var arr = [];

for(var i = 1; i < num + …

Read more


In JavaScript Reverse a String without using reverse()
Posted on November 12, 2017 in Algorithms, JavaScript by Matt Jennings

var str = ‘blah’;

function reverseStr(str1) {
var arr1 = str1.split(”);
var arr2 = [];

Read more


Using JavaScript Push Common Numbers from Two Arrays into a Third Array
Posted on July 31, 2015 in Algorithms, JavaScript by Matt Jennings

function commonIdsFromTwoArrays(arr1, arr2) {
// Array to push common IDs into
var commonIdsArr = [];

Read more