Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Uncompress Write a function uncompress(str) that takes in a compressed string as an arg. A compressed string consists of a character immediately followed by the

Uncompress Write a function uncompress(str) that takes in a "compressed" string as an arg. A compressed string consists of a character immediately followed by the number of times it appears in the "uncompressed" form. The function should return the uncompressed version of the string. See the examples. Hint: you can use the built-in Number function should convert a numeric string into the number type. For example. Number("4") // => 4

PLEASE try to debug what I am missing or doing a bit wrong. Try to fix what I currently have. NEEDs to be written in recursion and javascript. NEED THIS ASAP! Thanks!

My Approach:

let uncompress = function(str) {
let newStr = ''
if (!str.length) return newStr
let ele = str[0]
console.log(ele)
let first = Number([str.length + 1])
console.log(first)
if (first.includes(ele)) {
return uncompress(str.slice(0, str.length - 1))
}
return uncompress(str.slice(0, str.length -1)) + ele
}

console.log(uncompress('x3y4z2')); // 'xxxyyyyzz'
console.log(uncompress('a5b2c4z1')); // 'aaaaabbccccz'
console.log(uncompress('b1o2t1')); // 'boot'

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

System Dynamics

Authors: William Palm III

3rd edition

73398063, 978-0073398068

More Books

Students also viewed these Computer Engineering questions

Question

What is level mixed-model sequencing and why is it important?

Answered: 1 week ago

Question

To what extent has technology had an impact on JIT/lean systems?

Answered: 1 week ago