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 / 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 = {};
// --- 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 / 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++) {
@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 / 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 / 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 / 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;
function stringifier (input) {
if (typeof input === 'string') { //test for string, empty string
return '"' + input + '"';
}
if (typeof input === 'function' || typeof input === 'undefined') { // test for function or undefined
return undefined;
}
@Luke-Rogerson
Luke-Rogerson / AList.js
Last active May 3, 2018 14:35
AList - Eloquent Javascript, Chapter 4 - https://repl.it/@Luke_Rogerson/AList
/*
let list = {
value: 1,
rest: {
value: 2,
rest: {
value: 3,
rest: null
}
}