-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filled out README with some semi-useful information
- Loading branch information
Nicholas Rawlings
committed
Nov 23, 2013
1 parent
ef06742
commit 8e741c0
Showing
1 changed file
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
ArrayDiff | ||
========= | ||
|
||
Finds the difference between two JavaScript arrays by computing the longest common subsequence between them | ||
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. | ||
|
||
## Example | ||
|
||
```javascript | ||
var thisArray = 'nematode knowledge'.split(''), | ||
thatArray = 'empty bottle'.split(''), | ||
arrayDiff = new ArrayDiff(thatArray, thisArray); | ||
|
||
arrayDiff.diff.forEach(function(element) { | ||
|
||
if (element.added()) { | ||
var operation = '+' | ||
} else if (element.removed()) { | ||
var operation = '-'; | ||
} else { | ||
var operation = ' '; | ||
} | ||
|
||
console.log('%s %s', operation, element.item); | ||
|
||
}); | ||
``` | ||
|
||
|
||
## Acknowledgements | ||
|
||
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. |