Skip to content

Instantly share code, notes, and snippets.

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

Flavio Corpa kutyel

🌊
数学者に俺は成る!
View GitHub Profile
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
@kutyel
kutyel / catstagram_comments.json
Created November 15, 2018 12:06
JSON API for my Redux Workshop!
{
"1782228941182106890_3448238252": [
{
"from": {
"full_name": "rosaparksragdoll"
},
"text": "Hello Lovely 🐈🐾"
}
],
"1878968952505694822_3448238252": [
@kutyel
kutyel / jsx.re
Last active October 18, 2018 06:25
<ul>
{[|“foo”, “bar”, “baz”|]
->Belt.Array.mapWithIndex((key, x) => {let key = string_of_int(key); <li key>{ReasonReact.string(x)}</li>})
->ReasonReact.array}
</ul>
<ul>
{[“foo”, “bar”, “baz”].map((x, key) => <li key={key}>{x}</li>)}
</ul>
switch(city) {
| None => Js.log(“not found!”)
| Some(city) => Js.log(“found:” ++ city.name)
}