Skip to content

Commit

Permalink
Merge pull request #118 from AthulKkumar/js-coding-question
Browse files Browse the repository at this point in the history
feat: added an js coding question for non repating word in an text
  • Loading branch information
Ayu-hack authored Oct 8, 2024
2 parents 5b6030f + 56dc866 commit 161032b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions non_repating_word.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function firstNonRepeatedChar(str) {
const charCount = {};
for (const char of str) {
charCount[char] = (charCount[char] || 0) + 1;
}
for (const char of str) {
if (charCount[char] === 1) {
return char;
}
}
return null;
}

console.log(firstNonRepeatedChar("programming")); // Output: "p"

0 comments on commit 161032b

Please sign in to comment.