Remove the First and Last Characters

Published by Helen Yu in

Create a function that removes the first and last characters from a string.

Examples

remove_first_last("hello") ➞ "ell"

remove_first_last("maybe") ➞ "ayb"

remove_first_last("benefit") ➞ "enefi"

remove_first_last("a") ➞ "a"

Notes

For words with two or fewer letters (including an empty string), return the string itself (see example #4).

Watch a quick demo on how Edabit works.