Scramble String

Write a method that takes in a string and an array of indices in the string. Produce a new string, which contains letters from the input string in the order specified by the indices of the array of indices.

Screen Shot 2016-08-19 at 3.07.43 PM

Note the lack of ‘if’ statement and how idx is incremented inside the while loop.

Second time solving this:

It helps to write out the new string positions beforehand.

screen-shot-2016-09-19-at-5-15-27-pm

Third time doing this, I got a bit too creative but it worked:

screen-shot-2016-11-03-at-2-10-00-pm

Advertisements
Scramble String

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s