SOURCE

function testWord() {
    const slots = ["一", "", "", "", "", "", "", "", "", ""]; // Array of slots with 10 slots
    const idioms = ["一毛不拔", "一心一意", "虎虎生威", "一生一世", "欺三瞒四"];
    const slotsExcludeChars = [];
    let matchedIdiom = "";

    for (let currentIdiom of idioms) {
        const match = new Array(slots.length).fill(false); // Array length same as slots
        let matchedCharCount = 0;

        for (let i = 0; i < slots.length; i++) {
            if (slots[i] !== "" && currentIdiom.includes(slots[i])) {
                currentIdiom = currentIdiom.replace(slots[i], '');
                match[i] = true;
                matchedCharCount++;
                if (matchedCharCount === currentIdiom.length) break;
            }
        }

        if (matchedCharCount === currentIdiom.length) {
            console.log("Matched characters in slots (excluded characters):");
            for (let i = 0; i < 10; i++) {
                if (match[i]) {
                    console.log(slots[i]);
                    slotsExcludeChars.push(slots[i]);
                }
            }
            console.log("Matched idiom: " + currentIdiom);
            matchedIdiom = currentIdiom;
            break;
        }
    }
}

testWord()
console 命令行工具 X clear

                    
>
console