Skip to content

Commit

Permalink
reto-4
Browse files Browse the repository at this point in the history
  • Loading branch information
fernargdev committed Dec 13, 2023
1 parent ae35c62 commit b2dcc1a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
3 changes: 2 additions & 1 deletion retos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

<!-- <script src="reto-1.js"></script> -->
<!-- <script src="reto-2.js"></script> -->
<script src="reto-3.js"></script>
<!-- <script src="reto-3.js"></script> -->
<script src="reto-4.js"></script>
</body>

</html>
5 changes: 0 additions & 5 deletions retos/reto-3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
32 changes: 32 additions & 0 deletions retos/reto-4.js
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'))
14 changes: 14 additions & 0 deletions retos/reto-4.ts
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'))

0 comments on commit b2dcc1a

Please sign in to comment.