Change Strings in 2D Array Based on Conditions

You are given a two dimensional array containing arrays of strings as an argument. Each inner array contains a set of two string elements. The first element represents either an 'add' or a 'delete' change directive. The second element is a string that you will apply the directive with. Start out with an empty string, apply each set of change directives and return the resulting string.

'add' operations should add the given string to the end of the working string.

'delete' operations should remove all listed characters from the working string.


  • Must return a string

Example #1

solve(['add', 'oralllng'], ['delete', 'lll'], ['add', 'e']])
> 'orange'

  1. We start out with an empty string.
  2. The first directive is to add the string 'oralllng' to the empty string.
  3. Our string is now 'oralllng'
  4. The second directive is to delete the characters 'lll' from the string.
  5. Our string is now 'orang'
  6. The third directive is to add the letter 'e' which will be added to the end of our current string.
  7. Since there are no more inner arrays, we return our final string 'orange'