The first and last stop
- O(1) · Trivial
- Free
- Python
- JavaScript
- lists
- indexes
- strings
Problem
A bus route arrives as a list with the names of its stops in order, and all you care about are the two ends.
Write a function that returns a new list with two names: the first stop and the last one, in that order. With ["Downtown", "Hospital", "Market", "Airport"] you return ["Downtown", "Airport"].
A route can have any number of stops, but it is never empty. If it has a single stop, that one is the first and the last at the same time: with ["Old Mill"] you return ["Old Mill", "Old Mill"].
Examples
Four stops
["Downtown", "Hospital", "Market", "Airport"] → ["Downtown", "Airport"]
Only two stops
["North Gate", "South Gate"] → ["North Gate", "South Gate"]
Five stops
["Riverside", "Bell Tower", "Museum", "Garden", "Harbor"] → ["Riverside", "Harbor"]
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def ends(route):
passJavaScript
function ends(route) {
}It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.