Exploring Ruby Strings with a Twist

Welcome! In this lesson, we’ll delve into Ruby strings and explore a unique way of selecting characters. This task will help you refine your string manipulation skills in Ruby while engaging with an intriguing pattern of iteration.

Ready? Let’s get started!

The Task Statement

Imagine you’re given a string. Your job is to extract its characters in an unusual order: start with the first character, then jump to the last character, move to the second character, then to the second-to-last character, and so on until all characters are selected.

For example:

  • If the input string is "abcdefg", the output should be "agbfced".
  • For "hello", the output should be "hoell".

To achieve this, we’ll write a Ruby method called select_in_twist_order that takes an input string and returns the transformed string. The input string will:

  • Consist of lowercase English letters ('a' to 'z').
  • Have a length between 1 and 100 characters.

Let’s break this down step by step.

Step 1: Setting Up the Method

We start by defining the method and initializing an empty string to store the transformed output. The length of the input string will help us determine how many characters we need to process.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal