by Pawan Kumar @jsartisan
Create a function that accepts two string parameters s and t. The function should output true when the strings are anagrams of one another, and false if they're not.
Two strings are considered anagrams if you can shuffle the letters of one to create the other. For instance, "listen" and "silent" are anagrams because they use exactly the same letters the same number of times, just arranged differently.
Constraints:
- Both
sandtconsist of lowercase English letters.
Requirements:
- The function should take two arguments:
- A string
s. - A string
t.
- A string
- The function should return:
trueifsandtare anagrams.falseotherwise.
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