Skip to content

Instantly share code, notes, and snippets.

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

MelJones MoodyBones

🏠
Working from home
View GitHub Profile
HTML
- Semantic HTML
- Event delegation
- Accessibility / ARIA
CSS
- Specificity
- Pseudo-elements
- Pseudo-selectors
- Combinators
Data Structures
- Stacks
- Queues
- Linked lists
- Graphs
- Trees
- Tries
Concepts
- Big O Notation
@MoodyBones
MoodyBones / fill-array.js
Created January 5, 2021 16:01
Write a function that produces an array with the numbers 0 to N-1 in it.
const arr = N => Array.from({ length: N }, (_, i) => i)
// Notice that the first parameter of the function is the "length" just as when you get the arr.length , you define it.
// And the second parameter is the mapping function.
// Since our new array does not have items within it, we skip the first argument with _ and take the index i to return it => i as it will follow the linear increasing logic 0, 1, 2...
function diffArray(arr1, arr2) {
return [...arguments].reduce((a, c) => {
if (!arr1.includes(c) || !arr2.includes(c)) { a.push(c) }
return a
}, [])
}
console.log(diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5])) // [ 4 ]
@MoodyBones
MoodyBones / search-destroy.js
Created January 19, 2021 14:06
Search & remove elements from an array
function destroyer(arr) {
const destroyArgs = [...arguments].slice(1)
return arguments[0].filter((val) => {
return !destroyArgs.includes(val)
})
}
// const destroyer = (arr, ...valsToRemove) => arr.filter(elem => !valsToRemove.includes(elem));
@MoodyBones
MoodyBones / gist:01ee51b5e2b65dde7dba13f4cd1900e8
Created February 26, 2021 10:22 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
const countBits = (n) => n.toString(2).split('').filter(e => e === '1').length
@MoodyBones
MoodyBones / introrx.md
Created June 23, 2021 09:59 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@MoodyBones
MoodyBones / fisher-yates-shuffle.js
Created August 30, 2021 17:03
lodash shuffle is fisher-yates shuffle under the hood. I learnt this from Sarah Drasner.
function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1))
;[array[i], array[j]] = [array[j], array[i]]
}
return array
}
// Snippet by Sarah Drasner
// More shuffling ---> https://bost.ocks.org/mike/shuffle/
columnHeadingMap() {
return this.columnKeys.reduce((acc, curr, index) => {
acc[curr] = this.germanValues[index]
return acc
}, {})
},
// maps/reduces 2 arrays into an new object
// vue computed