Skip to content

Latest commit

 

History

History
33 lines (22 loc) · 895 Bytes

anagram-detection.md

File metadata and controls

33 lines (22 loc) · 895 Bytes

Anagram Detection 7 Kyu

LINK TO THE KATA - STRINGS FUNDAMENTALS

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"

Solution

const sortAlphabetically = word => {
  return word.toLowerCase().split('').sort().join('')
}

const isAnagram = (test, original) => {
  return sortAlphabetically(test) === sortAlphabetically(original)
}