📜  突变 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:15.198000             🧑  作者: Mango

代码示例1
// Mutations
// Return true if the string in the first element of the array contains all
// of the letters of the string in the second element of the array.
//For example, ["hello", "Hello"], should return true because all of the letters
// in the second string are present in the first, ignoring case.

function mutation(arr) {
    let second = arr[1].toLowerCase();
    let first = arr[0].toLowerCase();
    for (let i = 0; i < second.length; i++) {
        if (first.indexOf(second[i]) < 0) return false;
    }
    return true;
}

mutation(['floor', 'FLOOR']);

// OR

function mutation(arr) {
    return arr[1]
        .toLowerCase()
        .split('')
        .every(function (letter) {
            return arr[0].toLowerCase().indexOf(letter) != -1;
        });
}