Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

66 lines
1.3 KiB
Markdown

---
id: 69bc6cb30c1d112a2e110a04
title: "Challenge 247: Last Letter"
challengeType: 28
dashedName: challenge-247
---
# --description--
Given a string, return the letter from the string that appears last in the alphabet.
- If two or more letters tie for the last in the alphabet, return the first one.
- Ignore all non-letter characters.
# --hints--
`getLastLetter("world")` should return `"w"`.
```js
assert.equal(getLastLetter("world"), "w");
```
`getLastLetter("Hello World")` should return `"W"`.
```js
assert.equal(getLastLetter("Hello World"), "W");
```
`getLastLetter("The quick brown fox jumped over the lazy dog.")` should return `"z"`.
```js
assert.equal(getLastLetter("The quick brown fox jumped over the lazy dog."), "z");
```
`getLastLetter("HeLl0")` should return `"L"`.
```js
assert.equal(getLastLetter("HeLl0"), "L");
```
`getLastLetter("!#$ er@R asd fT.,> 2t0e9")` should return `"T"`.
```js
assert.equal(getLastLetter("!#$ er@R asd fT.,> 2t0e9"), "T");
```
# --seed--
## --seed-contents--
```js
function getLastLetter(str) {
return str;
}
```
# --solutions--
```js
function getLastLetter(str) {
const letters = str.split('').filter(char => /[a-zA-Z]/.test(char));
return letters.reduce((last, char) => char.toLowerCase() > last.toLowerCase() ? char : last);
}
```