본문 바로가기
알고리즘/Codewars

[Codewars] Anagram Detection (7 kyu) / JavaScript

by fluss 2023. 4. 6.

https://www.codewars.com/kata/529eef7a9194e0cbc1000255

 

Codewars - Achieve mastery through coding practice and developer mentorship

A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!

www.codewars.com

 

DESCRIPTION:

An anagram is the result of rearranging the letters of a word to produce a new word (see wikipedia).

Note: anagrams are case insensitive

Complete the function to return true if the two arguments given are anagrams of each other; return false otherwise.

 

Examples

  • "foefet" is an anagram of "toffee"
  • "Buckethead" is an anagram of "DeathCubeK"

 

코드

// write the function isAnagram
var isAnagram = function(test, original) {
  test = test.toUpperCase().split('').sort().join('');
  original = original.toUpperCase().split('').sort().join('');
  return test === original;
};

댓글