Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reto #11 - Javascript #2530

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Retos/Reto #11 - URL PARAMS [Fácil]/javascript/jmedinac1987.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
function getParamsValues(url) {
if (url === undefined) return ["Error: undefined"];

try {
let params = [];
let arrayText = [];
let arrayAux = [];

if (!url.includes("?")) return ["Error: no arguments"];
if (!url.includes("=")) return ["Error: arguments without values"];

arrayText = url.split("?");

if (arrayText[1].includes("&")) {
arrayAux = arrayText[1].split("&");

arrayAux.forEach((value) => {
params.push(value.split("=")[1]);
});

return params;
}

arrayAux = arrayText[1].split("=");

if (arrayAux.length > 2) {
return ['Error: multiple arguments without "&" separator'];
}
params.push(arrayAux[1]);

return params;
} catch (error) {
return [`Error: ${error}`];
}
}

//Tests
let testUrlOne = "https://test/_testPlans/define?planId=00001";
let testUrlTwo =
"https://test/test/acc/home/cxapp/support/agent/pay/system/tickets/list/all-cases?frameorigin=https%3A%2F%2Fone.testing.com&user=qa";
let testUrlThree =
"https://newinformation/_layouts/15/Doc.aspx?sourcedoc={befa3d19-a05d-4e1f-b2f9-cfcc013f8443}&action=edit&wd=target%28Test%20Data%20-%20Merchant%20Accounts.one%7C25d757ff-c6ff-4611-b28e-c80af9562c50%2FTest%20Data%20%E2%80%93%20Merchant%20Accounts%7C987d152e-6be3-406c-8a4d-8227369b6fba%2F%29&wdorigin=NavigationUrl";
let testUrlFour = "https://test/_testPlans/define";
let testUrlFive = "https://test/_testPlans/define?planId00001";
let testUrlSix = "https://test/_testPlans/define?planId=00001planId2=00002";

console.log(getParamsValues(testUrlOne));
console.log(getParamsValues(testUrlTwo));
console.log(getParamsValues(testUrlThree));
console.log(getParamsValues(testUrlFour));
console.log(getParamsValues(testUrlFive));
console.log(getParamsValues(testUrlSix));
console.log(getParamsValues());