This file contains 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
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! |
This file contains 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
// 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]) |
This file contains 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 text = " Levy " | |
text.trim() // > "Levy" | |
text.trimStart() // > "Levy " | |
text.trimEnd() // > " Levy" |
This file contains 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 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(" ") |
This file contains 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 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á! |
This file contains 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
git ls-files | grep \\.js$ | xargs wc -l |
This file contains 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
{ | |
"1782228941182106890_3448238252": [ | |
{ | |
"from": { | |
"full_name": "rosaparksragdoll" | |
}, | |
"text": "Hello Lovely 🐈🐾" | |
} | |
], | |
"1878968952505694822_3448238252": [ |
This file contains 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
<ul> | |
{[|“foo”, “bar”, “baz”|] | |
->Belt.Array.mapWithIndex((key, x) => {let key = string_of_int(key); <li key>{ReasonReact.string(x)}</li>}) | |
->ReasonReact.array} | |
</ul> |
This file contains 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
<ul> | |
{[“foo”, “bar”, “baz”].map((x, key) => <li key={key}>{x}</li>)} | |
</ul> |
This file contains 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
switch(city) { | |
| None => Js.log(“not found!”) | |
| Some(city) => Js.log(“found:” ++ city.name) | |
} |