Skip to content

Instantly share code, notes, and snippets.

View kutyel's full-sized avatar
🌊
数学者に俺は成る!

Flavio Corpa kutyel

🌊
数学者に俺は成る!
View GitHub Profile
module GoogleChart exposing (..)
import Html exposing (Html)
import Html.Attributes as HtmlA
import Json.Encode as E
import List.Extra as List
import Chart exposing (..)
colors =
@kutyel
kutyel / .babelrc
Created August 7, 2019 10:23
Personal JS options 😉🚀
{
"presets": [
"@babel/preset-react",
[
"@babel/preset-env",
{
"targets": {
"browsers": [
"last 2 versions",
"ie >= 11"
function sum(a, b) {
// Aquí puede haber comentarios importantes...
// ...sobre todo para gente que hace librerías, etc...
return a + b;
}
// En la primera versión de la especificación...
sum.toString() // > "function sum() { return a + b }"
Symbol('react').description // > "react"
Symbol.iterator.description // > "Symbol.iterator"
Symbol.for('preact').description // > "preact"
try {
// hacer algo útil...
} catch (err) {
// utilizar el parámetro `err` para algo...
}
try {
// ...más cosas útiles...
} catch {
// ...gestionar el error sin el parámetro!
@kutyel
kutyel / fromEntries.js
Last active August 2, 2019 09:53
Object.prototype.fromEntries()
// Supongamos, como ejemplo, que queremos elevar al cubo (^3) las habilidades de Eren
const eren = { strength: 50, health: 100, height: 170 }
// Utilizamos nuestro ya conocido método `Object.entries`
// para pasar del dominio de los objetos al de los arrays...
const aux = Object.entries(eren)
// > [["strength", 50], ["health", 100], ["height", 170]]
// Ahora que estamos en el dominio de los arrays, podemos hacer un simple `map`!
const array = aux.map(([key, value]) => [key, value ** 3])
@kutyel
kutyel / trim.js
Created August 2, 2019 09:22
String.trimStart/trimEnd()
const text = " Levy "
text.trim() // > "Levy"
text.trimStart() // > "Levy "
text.trimEnd() // > " Levy"
@kutyel
kutyel / flatMap.js
Last active August 2, 2019 08:21
Array.prototype.flatMap
const array = [1, 3]
const f = x => [x, x + 1]
array.map(f) // > [[1, 2], [3, 4]]
array.flatMap(f) // > [1, 2, 3, 4]
// Ahora un ejemplo un poco más curioso...
const heroes = ["Eren Jaeger", "Mikasa Ackerman"]
const splitBySpace = xs => xs.split(" ")
@kutyel
kutyel / flat.js
Created August 2, 2019 08:00
Array.prototype.flat()
const arr = [1, 2, 3, [4, 5]]
arr.flat() // > [1, 2, 3, 4, 5]
const arr1 = [1, 2, [3, 4, [5, 6]]]
arr1.flat(2) // > [1, 2, 3, 4, 5, 6]
const arr2 = [1, 2, [3, 4, [5, 6, [7, 8, [9, 10]]]]]
arr2.flat(Infinity) // > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
// Si tienes huecos vacíos en tu array también los limpiará!
@kutyel
kutyel / loc.sh
Last active May 9, 2019 10:22
Count lines of JS code in a repo
git ls-files | grep \\.js$ | xargs wc -l