Skip to content

Instantly share code, notes, and snippets.

@daybrush
Last active July 4, 2019 11:04
Show Gist options
  • Save daybrush/eca39b16b646cfef15a638e3594b482d to your computer and use it in GitHub Desktop.
Save daybrush/eca39b16b646cfef15a638e3594b482d to your computer and use it in GitHub Desktop.
const { removed, added, ordered, pureChanged,prevList, list } = result;
const nextList = prevList.slice();
removed.forEach(index => {
nextList.splice(index, 1);
});
ordered.forEach(([from, to], i) => {
nextList.splice(from, 1);
nextList.splice(to, 0, list[pureChanged[i][1]]);
});
added.forEach(index => {
nextList.splice(index, 0, list[index]);
});
// `nextList` is the same as `list`.
console.log(nextList, result.list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment