Skip to content

Instantly share code, notes, and snippets.

View Luke-Rogerson's full-sized avatar

Luke Rogerson Luke-Rogerson

View GitHub Profile
@Luke-Rogerson
Luke-Rogerson / index.js
Created September 23, 2018 14:43
mostFrequentWordChallenge created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/mostFrequentWordChallenge
const _ = require('lodash');
function highestWordCount (str) {
let resultArray = str.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()0-9]/g, "").split(' ');
let words = {};
for (word of resultArray) {
let counter = 0;
@Luke-Rogerson
Luke-Rogerson / index.js
Created September 23, 2018 14:43
mostFrequentWordChallenge created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/mostFrequentWordChallenge
const _ = require('lodash');
function highestWordCount (str) {
let resultArray = str.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()0-9]/g, "").split(' ');
let words = {};
for (word of resultArray) {
let counter = 0;
@Luke-Rogerson
Luke-Rogerson / main.js
Created September 29, 2018 12:30
InsertionSort created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/InsertionSort
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];
@Luke-Rogerson
Luke-Rogerson / main.js
Created September 29, 2018 12:31
InsertionSort created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/InsertionSort
// 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]) {
@Luke-Rogerson
Luke-Rogerson / index.js
Created September 29, 2018 13:44
SelectionSort created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/SelectionSort
// 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++) {
@Luke-Rogerson
Luke-Rogerson / index.js
Created September 29, 2018 14:04
SelectionSort created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/SelectionSort
// 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++) {
// --- 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) {
@Luke-Rogerson
Luke-Rogerson / Maxchar.js
Created December 12, 2018 22:32
Given a string, return the character that is most commonly used in the string.
// 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 = {};
@Luke-Rogerson
Luke-Rogerson / chunk.js
Created December 13, 2018 08:25
Given an array and chunk size, divide the array into many subarrays where each subarray is of length size
// --- 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]]
@Luke-Rogerson
Luke-Rogerson / anagrams.js
Created December 16, 2018 18:30
Check to see if two provided strings are anagrams of each other. One string is an anagram of another if it uses the same characters in the same quantity. Only consider characters, not spaces or punctuation. Consider capital letters to be the same as lower case
function anagrams(stringA, stringB) {
return cleanString(stringA) === cleanString(stringB);
}
function cleanString(str) {
return str
.replace(/[^\w]/g, '')
.toLowerCase()
.split('')
.sort()