-
Notifications
You must be signed in to change notification settings - Fork 0
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
ae35c62
commit b2dcc1a
Showing
4 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
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
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
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,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')) |
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,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')) |