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
// generate hint / score the guess
// 0 wrong, 1 right letter wrong place, 2 right letter right place
function generateHint(word: string, guess: string): string {
// spread word into array
const source = [...word]
// map guess
return [...guess].map((letter, i) => {
cardDeck = {
suits: ["♣️", "♦️", "♥️", "♠️"],
court: ["J", "Q", "K", "A"],
[Symbol.iterator]: function* () {
for (let suit of this.suits) {
for (let i = 2; i <= 10; i++) yield suit + i;
for (let c of this.court) yield suit + c;
}
}
}
<script>
export default {
data() {
return {
currentPage: 1,
articles: []
}
},
async fetch() {
const sumArrayReducer = (arr) => arr.reduce((a, b) => a + b, 0)
sumArrayReducer([1, 2, 3, 4, 5]) // 15
const reversedRangeArray = (num) => Array.from({ length: num }, (_, i) => num - i)
reversedRangeArray(5) // [5, 4, 3, 2, 1]
const rangeArray = (endNum) => Array.from({ length: endNum }, (_, i) => i + 1)
rangeArray(5) // [1, 2, 3, 4, 5]
sortBy(field) {
this.applicantsInfo.sort((a, b) => {
if (a[field] < b[field]) {
return -1
}
if (a[field] > b[field]) {
return 1
}
return 0
})
filteredNames() {
const key = 'name'
const filter = new RegExp(this.filterText, 'i')
return this.applicantsInfo.filter((el) => {
if (el[key] !== undefined) {
return el[key].toString().match(filter)
} else return true
})
},
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
@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/