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

fixed case-sensitivity of an anagram #903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kumarp149 wants to merge 1 commit into TheAlgorithms:master from kumarp149:patch-1
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions String/CheckAnagram.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ const checkAnagram = (str1, str2) => {
if (typeof str1 !== 'string' || typeof str2 !== 'string') {
return 'Not string(s)'
}

// If both strings have not same lengths then they can not be anagram.

if (str1.length !== str2.length) {
return false
}

// If both strings have not same lengths then they can not be anagrams

str1 = str1.toUpperCase();
str2 = str2.toUpperCase();

// Use hashmap to keep count of characters in str1

Expand All @@ -35,8 +39,6 @@ const checkAnagram = (str1, str2) => {
str1CharCount.set(str2[i], previousCount - 1)
}

// Now check if all entries in hashmap has zeros.

for (const key in str1CharCount) {
if (str1CharCount[key] !== 0) return false
}
Expand Down

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