0

I was asked this question by a big company. To my knowledge strings in JS are immutable. Hence, I can't do that. I was wondering if I am missing something. The interview was adamant not to create another var (string, array) and do it in-place.

input: 'harry'

output: 'hary'

I had to apologize and insist that I must create an array out of it and do the operations on it or create another empty string and push wanted chars to it.

Did I ruin my interview?

3
  • They are asking for an impossibility. Commented Jan 13, 2022 at 0:01
  • That company is a company that has a few of the most famous programming languages (came up with them.) I am surprised they would ask such a question. Perhaps they aren't familiar with JS. Commented Jan 13, 2022 at 0:04
  • Maybe they really meant to avoid temporary variables and values? You could perform solve the task by using string replacement with a regular expression. At least in user land that would be a single operation with temp variables/values. Commented Jan 13, 2022 at 10:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.