Anagram Detector
Function Name: areAnagrams
Description
An anagram is a word or phrase that's formed by rearranging the letters of another word or phrase. For example, 'listen' is an anagram of 'silent'.
Write a function 'areAnagrams' that takes two strings and returns a boolean indicating whether or not they are anagrams of each other.
The comparison should be case-insensitive and should disregard any non-alphabetical characters.
The function should focus on performance for larger strings.
Requirements
- The function should be named 'areAnagrams' and take exactly two parameters, both strings.
- The function should return a boolean: true if the strings are anagrams, false if they are not.
- Non-alphabetical characters should be ignored in the comparison.
- The comparison should be case-insensitive.
- Handling of spaces is important: spaces do not count toward the anagram property.
- Empty strings or strings with only non-alphabetical characters should be treated as not anagrams.
- The solution should handle large strings efficiently.
Examples
areAnagrams('listen', 'silent') // should return trueareAnagrams('Hello, world!', 'hello world') // should return trueareAnagrams('New York Times', 'monkeys write') // should return trueareAnagrams('Debit Card', 'Bad Credit') // should return trueareAnagrams('School master', 'The classroom') // should return trueareAnagrams('Astronomers', 'Moon starers') // should return trueareAnagrams('Conversation', 'Voices rant on') // should return trueareAnagrams('Listen', 'Silent') // should return trueareAnagrams('Hello, world!', 'Goodbye, world!') // should return falseareAnagrams('Batman', 'Manbat') // should return false, since it's a word for word comparison
Links
Area Code Extractor
Sat Aug 03 2024
Create a function named 'extractAreaCodes' that takes a string containing multiple phone numbers and extracts the area codes. Phone numbers can be in various formats, but area codes will always be the first three digits after an optional '+' and country code, or immediately following an opening parenthesis '('.The function should return a list of unique area codes in the order they appeared in the input string. Consider only extracting valid area codes (ranging from 200 to 999).Ignore any phone numbers that do not have a clear area code and handle varying formats and separators gracefully.
Duplicate Encoder
Mon Aug 05 2024
Write a function named 'encodeDuplicates' that takes a single string as its parameter.The function will transform the string into a new string where each lowercase character is replaced with '(' if that character appears only once in the original string, or with ')' if that character appears more than once in the original string.Ignore capitalization when determining if a character is a duplicate.The function should return the newly encoded string.