<?php

namespace Myrmidex\AnagramFinder;

use Illuminate\Support\Collection;

class Matcher
{
    public static function check(string $anagram, string $word): bool
    {
        $available = (new Collection(str_split($anagram)))->countBy();

        return (new Collection(str_split($word)))
            ->countBy()
            ->every(fn (int $needed, string $letter) => $available->get($letter, 0) >= $needed);
    }
}
