Skip to content

Instantly share code, notes, and snippets.

@spektraldevelopment
spektraldevelopment / startup.sh
Last active June 5, 2024 18:21
A simple AEM author start up script for local development
#!/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}"
@spektraldevelopment
spektraldevelopment / memoize.js
Created September 27, 2018 13:52
JS: Memoize
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
@spektraldevelopment
spektraldevelopment / matrix.js
Created September 25, 2018 15:06
JS: Spiralling Matrix
function matrix(n) {
const results = [];
for (let i = 0; i < n; i++) {
results.push([]);
}
let counter = 1;
let startColumn = 0;
let endColumn = n - 1;
@spektraldevelopment
spektraldevelopment / vowels.js
Last active September 24, 2018 20:16
JS: Vowels
function vowels(str) {
let vowelCount = 0;
[...str].forEach((char, i) => {
if (/[AEIOUaeiou]/.test(char) === true) {
vowelCount += 1;
}
});
@spektraldevelopment
spektraldevelopment / pyramid.js
Created September 21, 2018 19:20
JS: Pyramid
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) {
@spektraldevelopment
spektraldevelopment / steps.js
Created September 21, 2018 15:07
JS: Steps
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 += " ";
}
@spektraldevelopment
spektraldevelopment / capitalize.js
Created September 20, 2018 15:59
JS: Capitalize
function capitalize(str) {
const words = [];
for (let word of str.split(' ')) {
words.push(word[0].toUpperCase() + word.slice(1));
}
return words.join(' ');
}
@spektraldevelopment
spektraldevelopment / anagrams.js
Created September 20, 2018 15:38
JS: Anagrams
function anagrams(stringA, stringB) {
return cleanString(stringA) === cleanString(stringB)
}
function cleanString(str) {
return str.replace(/[^\w]/g, "").toLowerCase().split("").sort().join("");
}
@spektraldevelopment
spektraldevelopment / chunk.js
Created September 19, 2018 19:49
JS: Array Chunking
function chunk(array, size) {
const chunked = []
let index = 0;
while (index < array.length) {
chunked.push(array.slice(index, index + size));
index += size;
}
@spektraldevelopment
spektraldevelopment / fizzbizz.js
Last active September 18, 2018 18:52
JS: FizzBuzz
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');