Projects


Javascript Diff Algorithm

Using an idea grabbed from a mailing list post, I implemented the diff algorithm discussed in the following paper (free registration required):

P. Heckel, A technique for isolating differences between files
Comm. ACM, 21, (4), 264--268 (1978).

The implementation, itself, has two functions, one of which is recommended for use:

diffString( String oldFile, String newFile )
This method takes two strings and calculates the differences in each. The final result is the 'newFile' marked up with HTML (to signify both deletions from the oldFile and additions to the newFile).

Sample Code

document.body.innerHTML = diffString(
   "The red brown fox jumped over the rolling log.",
   "The brown spotted fox leaped over the rolling log"
);

Sample Output

The red brown spotted fox jumped leaped over the rolling log.

Projects Using this Code:

Downloads

Creative Commons License
This work is licensed under a Creative Commons Attribution 2.5 License.

Tags: algorithm, diff, javascript, papers, cool, popular

Current Projects

jQuery JavaScript Library

jQuery

Comprehensive DOM, Event, Animation, and Ajax JavaScript Library.

Recent Projects

Pro JavaScript Techniques

JavaScript Book

The best techniques for professional JavaScript. Published by Apress.


Hosting provided by the cool dudes at Engine Yard.