Skip to content

Commit

Permalink
Merge pull request #2527 from javierangosto/JavierAngostoReto11JS
Browse files Browse the repository at this point in the history
Reto #11 - Javascript
  • Loading branch information
Roswell468 authored Mar 14, 2023
2 parents b6ba041 + 0dda082 commit 0cd2a4c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Retos/Reto #11 - URL PARAMS [Fácil]/javascript/JavierAngosto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Dada una URL con parámetros, crea una función que obtenga sus valores.
* No se pueden usar operaciones del lenguaje que realicen esta tarea directamente.
*
* Ejemplo: En la url https://retosdeprogramacion.com?year=2023&challenge=0
* los parámetros serían ["2023", "0"]
*/

function getParameters( url = ""){
var result = [];
if ( url === '' || url.indexOf('?') === -1) return result;
var params = (url.substring(url.indexOf('?')+1, url.lenght)).split('&');
for( let i = 0; i < params.length; i++ ) {
result.push(params[i].substring(params[i].indexOf('=')+1, params[i].length));
}
return (result);
}

var url = "https://retosdeprogramacion.com?year=2023&challenge=0";

console.log(getParameters(url));

0 comments on commit 0cd2a4c

Please sign in to comment.