Anagram checker

Check whether an anagram contains all the letters in the source text.

Face with waiting expression Nothing to see yet!

Loading takeymakey...
TakeyMakey code
Want this tool to do something else? Edit the code below and make it do whatever you want.
({
  take: [
    { key: "anagram", type: "text", label: "Anagram text" },
    { key: "source", type: "text", label: "Source text" },
  ],
  make: ({ anagram, source }) => {
    anagram = anagram.toLowerCase().match(/[a-z]/g) || []
    source = source.toLowerCase().match(/[a-z]/g) || []

    let result = []
    let message = "Your anagram doesn't match yet."
    let value = false

    const diff = (a, b) =>
      a.filter((c) => {
        if (!b.includes(c)) return true
        b.splice(b.indexOf(c), 1)
        return false
      })

    const a = diff(anagram, [...source])
    const b = diff(source, [...anagram])

    if (a.length > 0) {
      result.push("It has these extra letters...")
      result.push(a.join("\t"))
    }

    if (b.length > 0) {
      result.push("It is missing some letters...")
      result.push(b.join("\t"))
    }

    if (a.length === 0 && b.length === 0) {
      value = true
      message = "Your anagram contains all the letters!"
    }

    return [
      { type: "status", value, message },
      result.length > 0 ? { type: "text", value: result.join("\n") } : null,
    ]
  },
})