What's missing in this code?
onlyOneSwap(['123', '132', '312', '321'], '123');
// [false, true, false, true];
onlyOneSwap(['BACDE', 'EBCDA', 'BCDEA', 'ACBED'], 'ABCDE');
// [true, true, false, false]
onlyOneSwap(['32145', '12354', '15342', '12543'], '12345');
// [true, true, true, true]
onlyOneSwap(['9786', '9788', '97865', '7689'], '9768');
// [true, false, false, false]
function onlyOneSwap(arr, original) {
return arr.map((word) => {
if (word.length
) return false;
let diffIndices = [];
for (let i = 0; i < word.length; i++) {
if (word[i] !== original[i]) diffIndices.push(i);
}
return (
diffIndices.length ===
&&
word[diffIndices[
]] === original[diffIndices[
]] &&
word[diffIndices[
]] === original[diffIndices[
]]
);
});
}
Type or select from these options