top of page
  • Writer's pictureCRM Science

Challenge 3: As Easy as A to B


It's back to school already for a lot of young developers out there. We though this would help them recall some of that knowledge that might have been lost over the summer.

A... B... shoot, what comes next?

Objective

This week's challenge is all about finding the easiest way to increment characters. How do you increment a string that is set to "A" to "B?" How about "S" to "T" and so on?

If only if it were as simple as "A" + 1. Or is it?

In the sample code, you'll be providing the body of a method that accepts two parameters:

  • Letter - a string of a single letter that you'll be incrementing

  • Step - an integer to control how far many steps the starting letter should be shifted.

Rules

1) Only worry about upper case

2) Z should wrap around to A (X, Y, Z, A, B, ...)

3) Funny guys/gals out there, A=B and variants aren't accepted!

Expected Results

  • getResult('A', 1) should yield "B" as B is 1 letter after A.

  • getResult('A',2) should yield "C" as C is two letters after A.

  • getResult('Z',1) should result in A, per the wrap around rule (#2 above)

Starter Code

You must use the following code and can only add to the code provided below.

Link to Code: Gist

Recent Posts
bottom of page