-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5dbc7a2
commit 0dda082
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
Retos/Reto #11 - URL PARAMS [Fácil]/javascript/JavierAngosto.js
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
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)); |