Implementation of spdiff in JS