Write a function that takes two strings s
and t
and returns true
if the two strings are anagrams of each other, and false
otherwise.
An anagram is a word or phrase formed by rearranging the letters of another, such as "racecar" and "carrace". Both strings must contain the same characters with the same frequency, but in any order.
Constraints:
s
and t
consist of lowercase English letters.Requirements:
s
.t
.true
if s
and t
are anagrams.false
otherwise.Example Usage:
// Example 1
const s1 = "racecar";
const t1 = "carrace";
console.log(areAnagrams(s1, t1)); // Output: true
// Example 2
const s2 = "jar";
const t2 = "jam";
console.log(areAnagrams(s2, t2)); // Output: false