Skip to content

Commit 8e741c0

Browse files
author
Nicholas Rawlings
committed
Filled out README with some semi-useful information
1 parent ef06742 commit 8e741c0

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
11
ArrayDiff
22
=========
33

4-
Finds the difference between two JavaScript arrays by computing the longest common subsequence between them
4+
ArrayDiff computes the difference between two JavaScript arrays (as well as any other object that uses numeric subscripts, such as a string or DOMNodeList) by finding the [longest common subsequence](https://en.wikipedia.org/wiki/Longest_common_subsequence_problem) between them.
5+
6+
## Example
7+
8+
```javascript
9+
var thisArray = 'nematode knowledge'.split(''),
10+
thatArray = 'empty bottle'.split(''),
11+
arrayDiff = new ArrayDiff(thatArray, thisArray);
12+
13+
arrayDiff.diff.forEach(function(element) {
14+
15+
if (element.added()) {
16+
var operation = '+'
17+
} else if (element.removed()) {
18+
var operation = '-';
19+
} else {
20+
var operation = ' ';
21+
}
22+
23+
console.log('%s %s', operation, element.item);
24+
25+
});
26+
```
27+
28+
29+
## Acknowledgements
30+
31+
Many thanks to [Professor David Eppstein](http://www.ics.uci.edu/~eppstein/) of the University of California, Irvine, whose [lecture notes](http://www.ics.uci.edu/~eppstein/161/960229.html) from February 1996 helped me get my head around the dynamic programming solution to the longest common subsequence problem.

0 commit comments

Comments
 (0)