When building scripts, it’s a common requirement to remove and update multiple items in a collection of strings. In this guide we’re going to mimic the process needed to take a list of require statements and generate a list of file names.


Implement a method that generates a list of file names based on a collection of require statements.

Exercise File

Code File

Exercise Description

Build a method that takes in an array of require statements and outputs an array of the file names with their JavaScript extension added.


javascript_files = [
  '//= require custom/scripts',
  '//= require base/defaults',
  '//= require html.sortable',
  '//= require moment',
  '//= require test-styles'

append_js_file_extension javascript_files

# Output

Real World Usage

Imagine that you were asked to build a feature that took in the contents of a file and you had to both remove and add content for each array element. This is a common requirement for tasks such as: building file parsers, developing view helper methods, and many more features.


Can be found on the solutions branch on github.


Please enter your comment!
Please enter your name here