Giter Site home page Giter Site logo

middle_character's Introduction

Middle Character Kata

Your job is to return the middle character of a word. If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters.

Requirements

The program runs in a repl like IRB or in the browser console

It's fine to use Ruby or JavaScript.

Acceptance Criteria

get_middle("test") # => "es"
get_middle("testing") # => "t"
get_middle("middle") # => "dd"
get_middle("A") # => "A"
get_middle("of") # => "of"

Getting Started

  1. Clone this repo https://github.com/k-ankobia/Middle_Character.git
  2. Change directory cd Middle Character
  3. Interact with the program in irb irb
  4. Load the program require ./lib/get_middle_letter
  5. Try it for yourself with any word

Process

I began my process by breaking down the requirements for the task into smaller steps and defining what inputs / outputs were expected. In addition to this i started thinking about data structure I would require and the logic behind solving the kata before writing any piece of code.

I wrote a very simple program that would allow me to solve the problem. I tested this using irb and passed the simplest tests before expanding on this further to meet the other requirements.

Red - Green - Refactor

Once I had a failing test, I then proceeded to write the code neccessary to pass the test. I played around in irb to to gain an insight into how i wanted my program to behave and TDD the necessary steps to get there.

Once the test had passed I committed my code and began refactoring by renaming classes.

After this, I proceeded to write the next set of test for words of even length. I then repeated my cycle of implementation.

The code that I wrote after did not pass as the return value included an extra character. This was as a result of how I was accessing the indices of the string. A quick change to range solved the problem.

Positives

=> Writing a plan of action before attempting to write code helped to structure what I wanted the program to do => Using requirements as template for tests => Interacting and playing with features tests in irb helped to structure the overall program.

Improve

=> Setup gemfile and short readme at the beginning.

First attempt video

middle_character's People

Contributors

k-ankobia avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.