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
#!/usr/bin/env bash | |
# For terminal output colors | |
GREEN="\033[1;32m" | |
NOCOLOR="\033[0m" | |
# Declare a variable to store the port number | |
port=4502 | |
echo -e "${GREEN}=============================================${NOCOLOR}" |
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 memoize(fn) { | |
const cache = {}; | |
return function (...args) { | |
//fast version of function | |
if(cache[args]) { | |
//if args are already in cache, return result | |
return cache[args]; | |
} | |
//Use slow function |
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 matrix(n) { | |
const results = []; | |
for (let i = 0; i < n; i++) { | |
results.push([]); | |
} | |
let counter = 1; | |
let startColumn = 0; | |
let endColumn = n - 1; |
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 vowels(str) { | |
let vowelCount = 0; | |
[...str].forEach((char, i) => { | |
if (/[AEIOUaeiou]/.test(char) === true) { | |
vowelCount += 1; | |
} | |
}); |
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 pyramid(n) { | |
const midpoint = Math.floor((2 * n - 1) / 2); | |
for (let row = 0; row < n; row++) { | |
let level = ''; | |
for (let column = 0; column < 2 * n - 1; column++) { | |
if (midpoint - row <= column && midpoint + row >= column) { |
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 steps(n) { | |
for (let row = 0; row < n; row++) { | |
let stair = ""; | |
for (let column = 0; column < n; column++) { | |
if (column <= row) { | |
stair += "#"; | |
} else { | |
stair += " "; | |
} |
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 capitalize(str) { | |
const words = []; | |
for (let word of str.split(' ')) { | |
words.push(word[0].toUpperCase() + word.slice(1)); | |
} | |
return words.join(' '); | |
} |
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().join(""); | |
} |
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 chunk(array, size) { | |
const chunked = [] | |
let index = 0; | |
while (index < array.length) { | |
chunked.push(array.slice(index, index + size)); | |
index += size; | |
} |
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 fizzBuzz(n) { | |
for(let i = 1; i <= n; i++) { | |
//Is the number a multiple of 3 and 5 | |
if(i % 3 === 0 && i % 5 === 0) { | |
console.log('fizzBuzz'); | |
} else if (i % 3 === 0) { | |
//Is the number a multiple of 3 | |
console.log('fizz'); |
NewerOlder