Reverse the portion of a string between two given indices

Photo by Monty Allen on Unsplash

We are going to write a function called solve that will accept a string, st, and two integers, a and b, as arguments.

You are given a string and two indices. The goal of the function is to reverse only the portion of the string between (and including) those indices and return the resulting string.

Example:

In the example above, we take the string and only reverse the section of the string from characters 1 to (and including) 5.

"c"   "odewa"    "rs""c"   "awedo"    "rs""cawedors"

After reversing the substring, the string is put back together…


The manager that could’ve turned a meeting into an email but never did

Once upon a time, a lady named Lily managed a small team of 4 at a marketing agency. She loved her job but her co-workers disagreed.

The problem with Lily was her obsession with meetings. She and her team would have as many as ten meetings a day. Almost all of the meetings could have been emails.


Return an array index where the sum of the left side of the index in the array is equal to the sum of the right side

Photo by Antoine Dautry on Unsplash

We are going to write a function called findEvenIndex that accepts an array, arr, as an argument.

You are given an array of integers. The purpose of the function is to take the array and return the index where the sum of the integers to the left of the index is equal to the sum of integers to the right of the index. If there is no such thing or if the array is empty, return -1.

Example:

If we look at the first example, the fourth number (index 3) is where…


A tale about series of car thieves that left a donut behind after stealing your car

Would you eat this donut after your car was stolen?

Once upon a time, there was a man named Wallace that had a car but one day he went outside and saw a donut instead of his car. His car disappeared. He couldn’t drive a donut so instead, he walked to work.

A friend of his saw him walk to work on the freeway and gave him a ride. His friend told him about getting a new car. The problem was every time Wallace bought a car it disappeared. He would buy a car and the next week it was gone. …


Create a function that will categorize new croquet club members based on data in an array

Photo by Alan Miller on Unsplash

We are going to write a function called openOrSenior that accepts a two-dimensional array, data, as an argument.

The Western Suburbs Croquet Club has two categories of membership, Senior and Open. You are given an array and each element is an array containing two numbers. The first number is the age of the member. The second number is their handicap.

To be a senior, the member has to be at least 55 years old and have a handicap greater than 7.

After evaluating the two numbers from each array element, the goal of the function is to determine whether each…


What it’s like to not live like a real mouse

Illustration made by the author.

Meet Wallace, the Computer Mouse. Wallace always wanted to be a real mouse. Unfortunately, instead of being a rodent, he’s a battery-operated object that has no purpose other than to click on things.

He doesn’t know what a mouse cursor is or what it looks like because he’s busy dragging his face and body on the desk. People tap their finger on him too much. They click, click, and click even when the computer is frozen. People slam him, toss him, drop him on the desk and on the floor. …


Counting the number of sheep present in an array

Photo by Tanner Yould on Unsplash

We are going to write a function called countSheeps that accepts an array, arrayOfSheep, as an argument.

You are given an array containing boolean values. The goal of the function is to return how many sheep are present. If the value is true that means the sheep is present.

Example:

countSheeps(array1); // output: 17

In the example above, there are 17 true values in the array so the function…


Meet Larry the snowglobe and his life as an object full of fake snow and fake water

Illustration made by the author.

Hello Larry, can you introduce yourself so people can know who you are?

Larry: …What’s there to know about me. I am a snowglobe born and manufactured in Iowa.

What do you love about being a snowglobe?

Larry: Nothing.

Can you elaborate?

Larry: No. I hate being a snowglobe. I hate Iowa and I hate this interview.

What made you hate being a snowglobe? People buy you during the holidays. Don’t you love it?

Larry: No. I hate being full of water, oil, and antifreeze. I hate being rattled and shaken to death so people can see tiny white stuff…


Capitalizing every word in a string

Photo by Brett Jordan on Unsplash

We are going to write a function called to_jaden_case that will accept a string, string, as an argument.

To begin with the origin of the function name, I’ll quote the instructions off of the Codewars algorithm page:

Jaden Smith, the son of Will Smith, is the star of films such as The Karate Kid (2010) and After Earth (2013). Jaden is also known for some of his philosophy that he delivers via Twitter. When writing on Twitter, he is known for almost always capitalizing every word.

You are given a string and the goal of the function is to return…


Creating a function that returns all numbers as negative

Photo by Gage Walker on Unsplash

We are going to write a function called makeNegative that will accept an integer, num, as an argument.

The goal of the function is to make num negative. If the input integer is already negative or zero, return the number as is.

Example:

The first thing we are going to do is write an if-statement that checks if num is a value that is less than or equal to zero. It wouldn’t make sense to make zero a negative and also if a number…

Erica N

An illustrator that writes humor and satire about everything and nothing at the same time.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store