Skip to content

Commit

Permalink
js Maps + js-snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
jolav committed Nov 4, 2024
1 parent 41ed6b1 commit bca4fd5
Show file tree
Hide file tree
Showing 25 changed files with 136 additions and 40 deletions.
15 changes: 15 additions & 0 deletions docs/javascript-snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ parseFloat(num.toFixed(3)); // return 6.77 , 6

## STRINGS

### Create UUIDv4

```js
// vale para el navegador y para nodejs
function generateUUID() {
const template = [1e7] + -1e3 + -4e3 + -8e3 + -1e11;
const uuid = template.replace(/[018]/g, function (c) {
const random = crypto.getRandomValues(new Uint8Array(1))[0];
const value = (c ^ random & 15 >> c / 4).toString(16);
return value;
});
return uuid;
}
```

### Clean whitespaces

```javascript
Expand Down
25 changes: 25 additions & 0 deletions docs/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,31 @@ console.log(domain.startsWith("www.")); // false

---

## MAPS

El **objeto `Map`** es una colección de pares clave-valor. Aquí hay algunas características clave:

- **Claves únicas**: Cada clave en un `Map` es única, lo que significa que no puede haber duplicados.

- **Iteración**: Puedes iterar sobre un `Map` utilizando un bucle `for...of`, que devuelve un array de dos elementos `[clave, valor]` en cada iteración.


- **Métodos útiles**: Algunos métodos importantes del objeto `Map` incluyen:
- `set(key, value)`: Agrega o actualiza un elemento con una clave y un valor.
- `get(key)`: Devuelve el valor asociado a la clave.
- `has(key)`: Verifica si una clave existe en el `Map`.
- `delete(key)`: Elimina un elemento por su clave.
- `clear()`: Elimina todos los elementos del `Map`.

```js
let mapa = new Map();
mapa.set('a', 1);
mapa.set('b', 2);
console.log(mapa.get('a')); // 1
```

---

## ARRAYS

Los arrays en Javascript son falsos arrays pero aun asi renta su uso
Expand Down
2 changes: 1 addition & 1 deletion www/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.496032+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.091277+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/css/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.532590+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.140263+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/debian/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2490,7 +2490,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.545368+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.154304+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/expressjs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.559770+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.172274+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.573941+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.185861+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/golang-bases-de-datos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.576912+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.188637+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/golang-para-web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.578644+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.190680+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/golang-snippets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2491,7 +2491,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.587277+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.199401+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/golang/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3125,7 +3125,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.595876+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.212144+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.616464+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.239539+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ <h3>Quick search</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.531545+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.139175+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/javascript-apis/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.622359+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.249412+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/javascript-para-web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.630298+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.270988+00:00
-->
</body>

Expand Down
24 changes: 23 additions & 1 deletion www/javascript-snippets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ <h3 id="remove-trailing-zeroes">remove trailing zeroes</h3>
</code></pre>
<hr />
<h2 id="strings">STRINGS</h2>
<h3 id="create-uuidv4">Create UUIDv4</h3>
<pre><code class="language-js">// vale para el navegador y para nodejs
function generateUUID() {
const template = [1e7] + -1e3 + -4e3 + -8e3 + -1e11;
const uuid = template.replace(/[018]/g, function (c) {
const random = crypto.getRandomValues(new Uint8Array(1))[0];
const value = (c ^ random &amp; 15 &gt;&gt; c / 4).toString(16);
return value;
});
return uuid;
}
</code></pre>
<h3 id="clean-whitespaces">Clean whitespaces</h3>
<pre><code class="language-javascript">function removeAllWhitespaces (str) {
return str.replace(/\s+/g, '');
Expand Down Expand Up @@ -588,6 +600,11 @@ <h3>Contenidos</h3>
<li><a href="#strings">STRINGS</a></li>
<ul>
<li><a href="#create-uuidv4">Create UUIDv4</a></li>
<ul>
</ul>
<li><a href="#clean-whitespaces">Clean whitespaces</a></li>
<ul>
Expand Down Expand Up @@ -911,6 +928,11 @@ <h3>Contenidos</h3>
<li><a href="#strings">STRINGS</a></li>
<ul>

<li><a href="#create-uuidv4">Create UUIDv4</a></li>
<ul>

</ul>

<li><a href="#clean-whitespaces">Clean whitespaces</a></li>
<ul>

Expand Down Expand Up @@ -1070,7 +1092,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.642204+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.297855+00:00
-->
</body>

Expand Down
36 changes: 35 additions & 1 deletion www/javascript/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,30 @@ <h3 id="metodos">Metodos</h3>
console.log(domain.startsWith(&quot;www.&quot;)); // false
</code></pre>
<hr />
<h2 id="maps">MAPS</h2>
<p>El <strong>objeto <code>Map</code></strong> es una colección de pares clave-valor. Aquí hay algunas características clave:</p>
<ul>
<li>
<p><strong>Claves únicas</strong>: Cada clave en un <code>Map</code> es única, lo que significa que no puede haber duplicados. </p>
</li>
<li>
<p><strong>Iteración</strong>: Puedes iterar sobre un <code>Map</code> utilizando un bucle <code>for...of</code>, que devuelve un array de dos elementos <code>[clave, valor]</code> en cada iteración.</p>
</li>
<li>
<p><strong>Métodos útiles</strong>: Algunos métodos importantes del objeto <code>Map</code> incluyen:</p>
</li>
<li><code>set(key, value)</code>: Agrega o actualiza un elemento con una clave y un valor.</li>
<li><code>get(key)</code>: Devuelve el valor asociado a la clave.</li>
<li><code>has(key)</code>: Verifica si una clave existe en el <code>Map</code>.</li>
<li><code>delete(key)</code>: Elimina un elemento por su clave.</li>
<li><code>clear()</code>: Elimina todos los elementos del <code>Map</code>.</li>
</ul>
<pre><code class="language-js">let mapa = new Map();
mapa.set('a', 1);
mapa.set('b', 2);
console.log(mapa.get('a')); // 1
</code></pre>
<hr />
<h2 id="arrays">ARRAYS</h2>
<p>Los arrays en Javascript son falsos arrays pero aun asi renta su uso <br />
Heredan de <code>Array.prototype</code> muchos metodos muy utiles</p>
Expand Down Expand Up @@ -1725,6 +1749,11 @@ <h3>Contenidos</h3>
</ul>
</ul>
<li><a href="#maps">MAPS</a></li>
<ul>
</ul>
<li><a href="#arrays">ARRAYS</a></li>
Expand Down Expand Up @@ -2093,6 +2122,11 @@ <h3>Contenidos</h3>

</ul>

</ul>

<li><a href="#maps">MAPS</a></li>
<ul>

</ul>

<li><a href="#arrays">ARRAYS</a></li>
Expand Down Expand Up @@ -2287,7 +2321,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.646968+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.302279+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/nodejs-bases-de-datos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.670367+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.337822+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/nodejs-snippets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.674482+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.341782+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/nodejs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.679788+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.346659+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/reactjs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ <h3>Contenidos</h3>

<!--
MkDocs version : 1.4.2
Docs Build Date UTC : 2024-10-14 20:03:25.683194+00:00
Docs Build Date UTC : 2024-11-04 17:28:47.351296+00:00
-->
</body>

Expand Down
2 changes: 1 addition & 1 deletion www/search/search_index.json

Large diffs are not rendered by default.

Loading

0 comments on commit bca4fd5

Please sign in to comment.