E28: The position of the element

In our last practice WOD, we dipped our toes into the waters stirred by Santiago Valdarrama in his blog post entitled five problems every software engineer should be able to solve in less than an hour.

For this practice WOD, we are going to solve another simple programming challenge he developed called the position of the element. Please take a look at his posting before going further.

As before, the goal of this WOD is only partially about Javascript; it is also intended to help you become efficient in your use of GitHub, git, and IntelliJ.

The WOD

For this practice WOD, please create a function called position that accepts a sorted array of integers and a target value. The position function returns the index where the target value is found, or if the target value is not found, returns the index where it would be if it were inserted in order. There won’t be duplicate values in the array. For example:

Ready? Let’s begin:

  1. Start your timer.

  2. Create an empty GitHub repo called “position” and clone it to your local computer.

  3. Create an IntelliJ “Static Web” project called “position” within your local position repo directory.

  4. Create two files: index.html and position.js. The index.html should load position.js. (You won’t use underscore for this WOD.)

  5. Implement the position function and test it on the sample invocations shown above.

  6. Commit your finished program to GitHub.

  7. Check that your code is on GitHub.

  8. Stop your timer and record your time. Be sure to record it, because you will need your WOD time data when you write your technical essay.

Rx: < 10 min Av: 10-12 min Sd: 12-15 min DNF: 15+ min

Demonstration

Once you’ve finished trying the WOD for the first time, watch me do it:

Standard WOD Caveats

You’ll learn significantly less from watching me solve the WOD if you haven’t attempted the WOD yourself first.

While it’s an achievement to finish the WOD no matter how long it takes, you might experience “diminishing returns” if you work longer than the DNF time. Thus, it is usually strategic to stop working at the DNF time and watch my solution.

After watching my solution, I recommend that you repeat the WOD if you have not achieved at least Av performance. If so, be sure to:

Feel free to keep trying until you make Rx if that’s of interest to you.

Submission Instructions

To be completed by the time and date indicated on the Schedule page.