list-diff
Introduction
Diff two lists in time O(n). I The algorithm finding the minimal amount of moves is Levenshtein distance which is O(n*m). This algorithm is not the best but is enougth for front-end DOM list manipulation.
This project is mostly influenced by virtual-dom algorithm.
Install
$ npm install list-diff2 --save
Usage
var diff = var oldList = id: "a" id: "b" id: "c" id: "d" id: "e"var newList = id: "c" id: "a" id: "b" id: "e" id: "f" var moves = // `moves` is a sequence of actions (remove or insert): // type 0 is removing, type 1 is inserting// moves: [// {index: 3, type: 0},// {index: 0, type: 1, item: {id: "c"}}, // {index: 0, type: 0}, // {index: 4, type: 1, item: {id: "f"}}// ] moves // now `oldList` is equal to `newList`// [{id: "c"}, {id: "a"}, {id: "b"}, {id: "e"}, {id: "f"}]console
License
MIT