Skip to content

Instantly share code, notes, and snippets.

View alDuncanson's full-sized avatar
🏠
Working from home

Al Duncanson alDuncanson

🏠
Working from home
View GitHub Profile
@alDuncanson
alDuncanson / index.js
Created June 3, 2020 16:41
Generate uppercase alphabet array
View index.js
const alphabet = [...Array(26)].map((_, index) => String.fromCharCode(index + 65))
@alDuncanson
alDuncanson / index.js
Created April 20, 2020 17:31
Convert military and standard times
View index.js
// 3:30 pm => 15:30
const standardToMilitary = standardTime => {
const [time, period] = standardTime.split(' ')
const [hours, minutes] = time.split(':')
if (period === 'am') {
return `${hours == 12 ? 24 : hours}:${minutes}`
} else {
return `${parseInt(hours) === 12 ? 12 : parseInt(hours) + 12}:${minutes}`
}
@alDuncanson
alDuncanson / index.js
Last active March 29, 2022 20:38
Get array of years up until current year (ex. yearsAgo(5) => [2018, 2019, 2020, 2021, 2022])
View index.js
const yearsAgo = year => Array.from([...Array(year)].fill(new Date().getFullYear()), (value, index) => value - index).reverse()