我正在尝试比较 2 个字符串是否相等,并返回不同位置的任何不同字母的数量,如果有任何例如bob和buy将返回 2。
我没有在其他地方找到任何其他示例,因此我尝试自己编写代码。我下面的代码没有返回任何东西,不确定它有什么问题?任何想法表示赞赏。
谢谢
    function equal(str1, str2) {
    /*If the lengths are not equal, there is no point comparing each character.*/
    if (str1.length != str2.length) {
        return false;
    }
    /*loop here to go through each position and check if both strings are equal.*/
    var numDiffChar = 0;
    var index = 0;
    while (index < str1.length) {
        if (str1.charAt(index) !== str2.charAt(index)) {
            numDiffChar += index;
            index++;
        } else {
            index++;
        }
    }
 };
 equal("javascript", "JavaScript");