diff algorithm implemented in JavaScript