Skip to content

Instantly share code, notes, and snippets.

View GabrielModog's full-sized avatar
🤠

Gabriel Tavares GabrielModog

🤠
View GitHub Profile
function high(x){
const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('')
const scores = alphabet.map((_, index) => index + 1)
const words = x.split(' ')
const scoresMap = scores.reduce((a, word, index) => a = Object.assign(a, {[alphabet[index]]: word}) , {})
const rankList = words.reduce((accum, curr) => {
const word = curr.split('').reduce((a, c, i) => a + scoresMap[c], 0)
return [...accum, word]
interface Todo {
title: string
description: string
completed: boolean
}
type MyPick<T, K extends keyof T> = {
[Key in K]: T[Key]
}
function arrayDiff(a, b) {
return a.filter((item)=>!b.includes(item))
}
function duplicateEncode(word) {
const encodeTree = {}
const characters = word.toLowerCase().split('')
const stringArray = []
for (let i = 0; i <= characters.length - 1; i++) {
const letter = characters[i]
if (encodeTree[letter] === undefined) {
encodeTree[letter] = 1
const sizes = [640, 800, 1200, 1440];
[
sizes.small,
sizes.big,
sizes.bigger,
sizes.large,
] = sizes;
@GabrielModog
GabrielModog / filter-with-options.ts
Last active March 6, 2022 02:59
you can filter a array that's have multi fields to match with
function filterWithOptions<T extends {[key: string]: Object}, O extends {[key: string]: string}>(array: Array<T>, filterOptions: O): Array<T>{
const filterOptionsKeys: string[] = Object.keys(filterOptions)
return array
.filter((item: T) =>
filterOptionsKeys
.every((key: string) => filterOptions[key] === item[key]))
}
// @gabrielmodog - 16:00 - 25-07-2021
const canvas = document.querySelector("canvas#app")
const context = canvas.getContext("2d")
const POINT_SIZE = 4
const POINT_CENTER_SIZER = POINT_SIZE * 2
const SCALE_RATE = 0.5
const rect = {
@GabrielModog
GabrielModog / faro-shuffle-deck.js
Created July 12, 2021 00:19
shuffle cards like faro
function faro(deck){
const half = deck.slice(0, deck.length / 2)
return deck
.slice(0, half)
.flatMap((card, index) => [card, deck[index + half]])
}
@GabrielModog
GabrielModog / remove-selected-option.js
Created July 7, 2021 03:49
helper to remove an item that's you already selected in a select element
function removeSelectedOptions(array, selected){
return array.filter((item) => !selected.includes(item))
}
@GabrielModog
GabrielModog / every-solution-1.js
Last active May 17, 2022 03:46
method to get boolean value with every item pass in the test
function every(array, test){
let bool = false
array.forEach(item => test(item) ? bool = true : bool = false)
return bool
}