Anagram Checker
JavaScript
easy
5 mins
Write a function that checks whether two input strings are anagrams of each other. An anagram is a word formed by rearranging the letters of another word, using all original letters exactly once.
Input: Two strings str1 and str2
Output: A boolean value – true if the strings are anagrams, false otherwise.
Example Inputs & Outputs
// Example 1: Input: ("listen", "silent") Output: true // Example 2: Input: ("hello", "world") Output: false // Example 3: Input: ("Triangle", "Integral") Output: true // Example 4: Input: ("rat", "car") Output: false // Example 5: Input: ("a", "A") Output: true // Example 6: Input: ("dormitory!!", "dirty room") Output: true
Constraints & Edge Cases
- The comparison should be case-insensitive.
- Both strings may contain non-alphabetic characters (optional: ignore them).
- Empty strings are valid inputs.
- Strings of different lengths can’t be anagrams.
- Whitespaces are ignored and compare only letters
Solve Similar questions 🔥
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
