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

If the string is equal to or fewer than 2 characters long, return the string itself.

Watch a quick demo on how Edabit works.