From b2dcc1a2a7546c42e015c1095eca69dd46122b89 Mon Sep 17 00:00:00 2001 From: fernargdev <115408504+fernargdev@users.noreply.github.com> Date: Wed, 13 Dec 2023 02:59:39 -0500 Subject: [PATCH] reto-4 --- retos/index.html | 3 ++- retos/reto-3.ts | 5 ----- retos/reto-4.js | 32 ++++++++++++++++++++++++++++++++ retos/reto-4.ts | 14 ++++++++++++++ 4 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 retos/reto-4.js create mode 100644 retos/reto-4.ts diff --git a/retos/index.html b/retos/index.html index 23a4346..9fd8ac6 100644 --- a/retos/index.html +++ b/retos/index.html @@ -11,7 +11,8 @@ - + + \ No newline at end of file diff --git a/retos/reto-3.ts b/retos/reto-3.ts index 6dae272..0923f77 100644 --- a/retos/reto-3.ts +++ b/retos/reto-3.ts @@ -9,8 +9,3 @@ function findNaughtyStep(original: [], modified: []) { if (original[i] !== modified[i]) return max[i] } } - -const original = 'abcd' -const modified = 'abcde' - -// console.log(findNaughtyStrp(original, modified)) diff --git a/retos/reto-4.js b/retos/reto-4.js new file mode 100644 index 0000000..466dcbc --- /dev/null +++ b/retos/reto-4.js @@ -0,0 +1,32 @@ +/* eslint-disable no-unused-vars */ +/* eslint-disable space-before-function-paren */ +// function decode(message: string) { +// if (message.length === 0) { +// return '' +// } + +// const newMessage = new Array() +// const array = message.split('') + +// for (let i = 0; i < array.length; i++) { +// if (array[i] !== '(') { +// newMessage.push(array[i]) +// } + +// } +// } + +// // Recursividad +// function decode(message) { +// const match = message.match(/\(\w*\)/) + +// if (!match) return message + +// const clean = match[0].slice(1, -1) +// const revert = clean.split('').reverse().join('') +// const result = message.replace(match[0], revert) + +// return decode(result) +// } + +// console.log(decode('sa(u(cla)atn)s')) diff --git a/retos/reto-4.ts b/retos/reto-4.ts new file mode 100644 index 0000000..3fba3ba --- /dev/null +++ b/retos/reto-4.ts @@ -0,0 +1,14 @@ +// Recursividad +function decode(message: string) { + const match = message.match(/\(([^()]+)\)/) + + if (!match) return message + + const clean = match[0].slice(1, -1) + const revert = clean.split('').reverse().join('') + const result = message.replace(match[0], revert) + + return decode(result) +} + +console.log(decode('sa(u(cla)atn)s'))