Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 184e83e

Browse files
committed
Add a question
1 parent feed510 commit 184e83e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

‎README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,3 +1751,42 @@ const domainName = url => {
17511751
---
17521752

17531753
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**
1754+
1755+
## 52. First Non-repeating Character
1756+
1757+
Write a function that takes an input string and returns the first character that is not repeated anywhere in the string. Upper- and lowercase letters are considered the same character, but the function should return the correct case for the initial letter.
1758+
1759+
```js
1760+
const firstNonRepeatingLetter = str => {
1761+
// Your solution
1762+
};
1763+
1764+
console.log(firstNonRepeatingLetter('a')); // 'a'
1765+
console.log(firstNonRepeatingLetter('stress')); // 't'
1766+
console.log(firstNonRepeatingLetter('sTreSS')); // 'T'
1767+
console.log(firstNonRepeatingLetter('abba')); // ''
1768+
console.log(firstNonRepeatingLetter("Go hang a salami, I'm a lasagna hog!")); // ','
1769+
```
1770+
1771+
<details><summary>Solution</summary>
1772+
1773+
```js
1774+
const firstNonRepeatingLetter = str => {
1775+
const strToLower = str.toLowerCase();
1776+
for (let char of str) {
1777+
if (
1778+
strToLower.indexOf(char.toLowerCase()) ===
1779+
strToLower.lastIndexOf(char.toLowerCase())
1780+
) {
1781+
return char;
1782+
}
1783+
}
1784+
return '';
1785+
};
1786+
```
1787+
1788+
</details>
1789+
1790+
---
1791+
1792+
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /