Skip to content

Instantly share code, notes, and snippets.

View inodaf's full-sized avatar
👨‍🚀
Starfleet Command

Isac Fadoni inodaf

👨‍🚀
Starfleet Command
  • Senior Software Engineer · @n26
  • Berlin, Germany
  • 06:00 (UTC +02:00)
View GitHub Profile
@inodaf
inodaf / intersection.js
Created June 28, 2019 12:20
Find Intersection in Array
const intersection = (a, b) =>
a.map(ai => b.filter(bi => bi === ai)).flat()
intersection(['banana', 'apple'], ['banana', 'mellon']) // ['banana']
intersection(['banana', 'apple'], ['banana', 'mellon', 'apple']) // ['banana', 'apple']
@inodaf
inodaf / imagefilter.js
Created July 12, 2019 20:48
Grayscale and Inversion Filters for Images
const grayscale = pixel => {
const [r, g, b] = pixel.data
const average = (r + g + b) / 3
pixel.data[0] = average
pixel.data[1] = average
pixel.data[2] = average
return pixel
}
@inodaf
inodaf / name-capitals.js
Created April 12, 2020 20:52
Getting Name Capitals in JavaScript
const splitWords = phrase => phrase.split(' ')
const firstLetter = word => word.charAt(0)
const lastLetter = word => word.charAt(word.length - 1)
const initialLetter = words => words
.map(word => word.charAt(0))
.join('')
const firstAndLastLetter = word => [
firstLetter(word),
@inodaf
inodaf / getting-started.md
Last active June 24, 2020 19:57
🏖 Pending Responses for Fetch API.

Awaits for a pending response with a single line.

const { status, data, error } = await parseResponse(fetch('/resource')))
@inodaf
inodaf / hourglass.ts
Last active January 12, 2021 15:34
Data Structures: Array
const twoDimensionsArray = [
[-9, -9, -9, 1, 1, 1],
[ 0, -9, 0, 4, 3, 2],
[-9, -9, -9, 1, 2, 3],
[ 0, 0, 8, 6, 6, 0],
[ 0, 0, 0, -3, 0, 0],
[ 0, 0, 1, 2, 4, 0],
]
const twoDimensionsArray2 = [
@inodaf
inodaf / generate.js
Created January 12, 2021 19:42
Generate an Array with Random Numbers in JavaScript
const generate = (length = 1000) => Array(length).fill().map(() =>
Math.floor(Math.random() * Math.floor(100))
)
@inodaf
inodaf / _minmax.ts
Last active January 12, 2021 21:07
Get the Minimum & Maximum Number from an Array in JavaScript
function min(target: Array<Number>): Number {
const reducer = (lowerest, current) => current < lowerest ? current : lowerest
return target.reduce(reducer)
}
function max(target: Array<Number>): Number {
const reducer = (greatest, current) => current > greatest ? current : greatest
return target.reduce(reducer)
}
function max(target: Array<Number>): Number {
const reducer = (greatest, current) => current > greatest ? current : greatest
return target.reduce(reducer)
}
function crush(length, queries) {
const zeroes = Array(length).fill(0)
for (let i = 0; i < queries.length; i++) {
const [a, b, k] = queries[i];
@inodaf
inodaf / fib.js
Last active January 25, 2021 20:22
Fibonacci: Exponential vs Dynamic Programming using Memoizers
const fib = n => {
if (n <= 2) return 1
return fib(n - 1) + fib(n - 2)
}
function fib2(n, mem = {}) {
let fibonacci;
if (n in mem) return mem[n]
fibonacci = n <= 2 ? 1 : fib2(n - 1, mem) + fib2(n - 2, mem)
// O(logn)
const binarySearch = (list: number[], item) => {
let [from, to] = [0, list.length - 1];
if (!item) return
while (from <= to) {
const index = Math.ceil((from + to) / 2);
const guess = list[index];