The last four
- O(1) · Trivial
- Free
- Python
- JavaScript
- strings
- indexes
Problem
A receipt never shows the whole card: only its last four digits. Write a function that takes the card number as text and returns those last four: with "4539123456789012" you return "9012".
The answer is text, not a number, so a leading zero stays. And if the card has four digits or fewer, you return all of it.
Examples
"4539123456789012" → "9012"
Starting with a zero
"987650012" → "0012"
Exactly four
"5555" → "5555"
"12345" → "2345"
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def last_four(card):
passJavaScript
function lastFour(card) {
}Solve this challenge
It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.