Skip to content

Instantly share code, notes, and snippets.

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

hacknlove hacknlove

🏠
Working from home
View GitHub Profile
@hacknlove
hacknlove / cardinalidadDelConjuntoPotenciaDeLosNaturales.py
Created March 7, 2020 12:37
Biyección entre los números naturales y el conjunto potencia de los números naturales
def nextSet (s):
"""
Esta función obtiene el siguiente subconjunto al subconjunto dado
"""
decrement = len(s) - 1
if decrement == -1:
return [0]
increment = decrement
while True:
increment -=1
@hacknlove
hacknlove / flatten.js
Created September 16, 2019 10:23
flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4]
/**
* flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
* @param {[number]} from array to be flatternd
* @param {[number]} [to] array where integers are placed. Defaults to [], and it is used only for recursion.
* @return {[number]} flattern array
*/
function flatten (from, to = []) {
from.forEach(value => {
if (Array.isArray(value)) {
@hacknlove
hacknlove / useStorage.js
Created July 2, 2019 11:51
Custom react hook useStorage for browser extension developers
import browser from 'webextension-polyfill'
import { useState, useEffect } from 'react'
function isDiferent (a, b) {
if (typeof a !== typeof b) {
return true
}
if (Array.isArray(a)) {
return arrayIsDifferent(a, b)
}