Skip to content

Commit

Permalink
Reto #11 - Javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
javierangosto committed Mar 13, 2023
1 parent 5dbc7a2 commit 0dda082
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 0dda082

Please sign in to comment.