Red Stapler Code Example C3

by Red Stapler

JavaScript

function findDiff(str1, str2) {
  let diff = "";
  str2.split('').forEach(function(val, i) {
    if (val != str1.charAt(i)) diff += val;
  });
  return diff;
}

let diff = findDiff("test-abc-te1t", "test-123-test");
console.log(diff);