This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function flat(array){ | |
| return array.reduce((accumulator, current) => { | |
| accumulator.push(...current) | |
| return accumulator | |
| }, []) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Queue(){ | |
| const list = [] | |
| return { | |
| add(item){ | |
| list.unshift(item) | |
| return item | |
| }, | |
| remove(){ | |
| return list.pop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function map(array, transform){ | |
| let shaped = [] | |
| for(let element of array){ | |
| mapped.push(transform(element)) | |
| } | |
| return shaped | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function arrayToList(arr){ | |
| let list = {} | |
| arr.forEach(item => { | |
| const newValue = { | |
| value: item, | |
| rest: Object.entries(list).length ? null : list, | |
| } | |
| list = newValue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function formatColorAndSize(list){ | |
| return list.reduce((accum, colorAndSize) => { | |
| const [color, size] = colorAndSize.split('-') | |
| accum[color] = accum[color] || {} | |
| accum[color][size] = accum[color][size] || 0 | |
| accum[color][size] += 1 | |
| return accum | |
| }, {}) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Listener<EventType> = (evt: EventType) => void; | |
| function createObserver<EventType>(): { | |
| subscribe: (listener: Listener<EventType>) => () => void; | |
| publish: (event: EventType) => void; | |
| } { | |
| let listeners: Listener<EventType>[] = []; | |
| return { | |
| subscribe: (listener: Listener<EventType>): (() => void) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const original = | |
| `v=0 | |
| o=bulma bulma@capsule.corporation.com | |
| s= | |
| t=0 | |
| m=audio 123 rtp | |
| a=128kbps | |
| a=no-echo | |
| a=filters | |
| a=dragon-effect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function animalStrategy(name){ | |
| const types = { | |
| dog: { | |
| name: 'Dog', | |
| race: 'Dog', | |
| version: '1.3', | |
| id: 'doggod', | |
| noise: () => 'bark bark bark', | |
| }, | |
| cat: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fixCurrencyToBRL = (num) => { | |
| if (typeof num === "string") { | |
| if (num.includes(",")){ | |
| const prepared = num.replace(/[.*]/g, ''); | |
| return Number(prepared.replace(/,/g, ".")) | |
| .toLocaleString("pt-br", { minimumFractionDigits: 2 }); | |
| } | |
| const fixed = Number( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fibonacci = (num, memo = {}) => { | |
| if(num in memo) return memo[num]; | |
| if(num <= 2) return 1; | |
| memo[num] = fibonacci(num - 1, memo) + fibonacci(num - 2, memo) | |
| return memo[num]; | |
| } |