Blog

Archive for the JavaScript Category


Code to Get Unique Elements of an Array using ES6 Syntax
Posted on February 6, 2019 in Algorithms, JavaScript by Matt Jennings

const arr1 = [2, 2, 4, 2, 6, 4, 7, 8]

const counts = {}

let i

for (i = 0; i < …

Read more


Determine if a String Contains a Palindrome in JavaScript
Posted on December 7, 2017 in Algorithms, JavaScript, Regular Expressions by Matt Jennings

Determine if a string contains a palindrome in JavaScript.
Strip out any non Latin alphabetic characters if needed.

var str = ‘!Noel …

Read more


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