From ec2fb3721b20b9bd3bc483699ea3dcd289875af4 Mon Sep 17 00:00:00 2001 From: jmedinac1987 Date: Mon, 13 Mar 2023 19:28:15 -0500 Subject: [PATCH] Reto #11 - Javascript --- .../javascript/jmedinac1987.js" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "Retos/Reto #11 - URL PARAMS [F\303\241cil]/javascript/jmedinac1987.js" diff --git "a/Retos/Reto #11 - URL PARAMS [F\303\241cil]/javascript/jmedinac1987.js" "b/Retos/Reto #11 - URL PARAMS [F\303\241cil]/javascript/jmedinac1987.js" new file mode 100644 index 0000000000..45fd3dc013 --- /dev/null +++ "b/Retos/Reto #11 - URL PARAMS [F\303\241cil]/javascript/jmedinac1987.js" @@ -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());