This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require('lodash'); | |
function highestWordCount (str) { | |
let resultArray = str.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()0-9]/g, "").split(' '); | |
let words = {}; | |
for (word of resultArray) { | |
let counter = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require('lodash'); | |
function highestWordCount (str) { | |
let resultArray = str.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()0-9]/g, "").split(' '); | |
let words = {}; | |
for (word of resultArray) { | |
let counter = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function insertionSort (arr) { | |
let temp = []; | |
for (let i = 1; i < arr.length; i++) { | |
for (let j = 0; j < i; j++) { | |
// console.log(arr[j]); | |
if (arr[i] < arr[j]) { | |
temp[0] = arr[i]; | |
arr[i] = arr[j]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An implementation of a basic insertion sort. | |
function insertionSort(arr) { | |
let temp = []; | |
for (let i = 1; i < arr.length; i++) { | |
for (let j = 0; j < i; j++) { | |
// console.log(arr[j]); | |
if (arr[i] < arr[j]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A simple selection sort algorithm | |
function selectionSort (arr) { | |
let minIndex = 0; | |
let temp = 0; | |
for (let i = 0; i < arr.length; i++) { | |
minIndex = i; | |
for (let j = i + 1; j < arr.length; j++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A simple selection sort algorithm | |
function selectionSort(arr) { | |
let minIndex = 0; | |
let temp = 0; | |
for (let i = 0; i < arr.length; i++) { | |
minIndex = i; | |
for (let j = i + 1; j < arr.length; j++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --- Directions | |
// Given a string, return true if the string is a palindrome | |
// or false if it is not. Palindromes are strings that | |
// form the same word if it is reversed. *Do* include spaces | |
// and punctuation in determining if the string is a palindrome. | |
// --- Examples: | |
// palindrome("abba") === true | |
// palindrome("abcdefg") === false | |
function palindrome(str) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given a string, return the character that is most | |
// commonly used in the string. | |
// --- Examples | |
// maxChar("abcccccccd") === "c" | |
// maxChar("apple 1231111") === "1" | |
function maxChar(str) { | |
const charMap = {}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --- Directions | |
// Given an array and chunk size, divide the array into many subarrays | |
// where each subarray is of length size | |
// --- Examples | |
// chunk([1, 2, 3, 4], 2) --> [[ 1, 2], [3, 4]] | |
// chunk([1, 2, 3, 4, 5], 2) --> [[ 1, 2], [3, 4], [5]] | |
// chunk([1, 2, 3, 4, 5, 6, 7, 8], 3) --> [[ 1, 2, 3], [4, 5, 6], [7, 8]] | |
// chunk([1, 2, 3, 4, 5], 4) --> [[ 1, 2, 3, 4], [5]] | |
// chunk([1, 2, 3, 4, 5], 10) --> [[ 1, 2, 3, 4, 5]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function anagrams(stringA, stringB) { | |
return cleanString(stringA) === cleanString(stringB); | |
} | |
function cleanString(str) { | |
return str | |
.replace(/[^\w]/g, '') | |
.toLowerCase() | |
.split('') | |
.sort() |