Back to all solutions

#242 - Valid Anagram

Problem Description

Given two strings s and t, return true if t is an anagram of s, and false otherwise.

Solution

/**
 * @param {string} s
 * @param {string} t
 * @return {boolean}
 */
var isAnagram = function(s, t) {
  const sort = str => str.split('').sort().join('');
  return sort(s) === sort(t);
};