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 / VowelCount.js
Last active May 1, 2018 05:41
VowelCount algorithm challenge created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/VowelCount
/*
Vowel Count *
* Using the JavaScript language, have the function VowelCount(str) take the str *
* string parameter being passed and return the number of vowels the string contains *
* (ie. "All cows eat grass" would return 5). Do not count y as a vowel for this *
* challenge.
*/
// Split sentence into array
//
@Luke-Rogerson
Luke-Rogerson / AlphabetSoup.js
Last active May 1, 2018 05:43
AlphabetSoup algorithm challenge created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/AlphabetSoup
/*
have the function AlphabetSoup(str) take the str string parameter being passed and return the string with the letters in alphabetical order (ie. hello becomes ehllo). Assume numbers and punctuation symbols will not be included in the string.
*/
function AlphabetSoup(str) {
var strArray = str;
return strArray.split("").sort().join("");
}
@Luke-Rogerson
Luke-Rogerson / LongestWord.js
Created May 1, 2018 05:44
LongestWord algorithm challenge created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/LongestWord
/*
have the function LongestWord(sen) take the sen parameter being passed and return the largest word in the string. If there are two or more words that are the same length, return the first word from the string with that length. Ignore punctuation and assume sen will not be empty.
*/
function LongestWord(sen) {
let longestWord = "";
let sentence = sen.match(/[a-z0-9]+/gi);
// let sentenceArray = sentence.split(" ");
console.log(sentence);
/*
Have the function TimeConvert(num) take the num parameter being passed and return the number of hours and minutes the parameter converts to (ie. if num = 63 then the output should be 1:3). Separate the number of hours and minutes with a colon.
Input:126
Output:"2:6"
Input:45
Output:"0:45"
/*
have the function CheckNums(num1,num2) take both parameters being passed and return the string true if num2 is greater than num1, otherwise return the string false. If the parameter values are equal to each other then return the string -1.
*/
function CheckNums (num1, num2) {
if (num2 > num1) {
return true;
}
else if (num1 == num2) {
return -1;
/*
Have the function LetterCapitalize(str) take the str parameter being passed and capitalize the first letter of each word. Words will be separated by only one space.
*/
function LetterCapitalize (str) {
let wordArray = str.split(" ");
capitalize = function (word) {
return word.charAt(0).toUpperCase() + word.slice(1);
// Eloquent Javascript, Chapter 4, Coding Challenge #1
/* Write a range function that takes two arguments, start and end, and returns an array containing all the numbers from start up to (and including) end. */
function range (start, end, step) {
let rangeArray = [];
for (let i = start; i <= end; i += step) {
rangeArray.push(i);
// Eloquent Javascript, Chapter 4, Coding Challenge #2
/*Arrays have a reverse method which changes the array by inverting the order in which its elements appear. For this exercise, write two functions, reverseArray and reverseArrayInPlace. The first, reverseArray, takes an array as argument and produces a new array that has the same elements in the inverse order. The second, reverseArrayInPlace, does what the reverse method does: it modifies the array given as argument by reversing its elements. Neither may use the standard reverse method.*/
function reverseArray (array) {
let newArray = [];
for (let i = array.length; i >= 0; i--) {
newArray.push(i);
}
@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
}
}
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;
}