JSFiddle - React, Tailwind, and code Playground

by pierian_design

JavaScript

var diff_linesToChars_ = function(text1, text2) {
        var lineArray = [];  // e.g. lineArray[4] == 'Hello\n'
        var lineHash = {};   // e.g. lineHash['Hello\n'] == 4

        // '\x00' is a valid character, but various debuggers don't like it.
        // So we'll insert a junk entry to avoid generating a null character.
        lineArray[0] = '';

        /**
         * Split a text into an array of strings.  Reduce the texts to a string of
         * hashes where each Unicode character represents one line.
         * Modifies linearray and linehash through being a closure.
         * @param {string} text String to encode.
         * @return {string} Encoded string.
         * @private
         */
        function diff_linesToCharsMunge_(text) {
            var chars = '';
            // Walk the text, pulling out a substring for each line.
            // text.split('\n') would would temporarily double our memory footprint.
            // Modifying text would create many large strings to garbage collect.
            var lineStart = 0;
            var lineEnd = -1;
            // Keeping our own length variable is faster than looking it up.
            var lineArrayLength = lineArray.length;
            while (lineEnd < text.length - 1) {
                lineEnd = text.indexOf(' ', lineStart);
                if (lineEnd == -1) {
                    lineEnd = text.length - 1;
                }
                var line = text.substring(lineStart, lineEnd + 1);
                
                console.log('line', line);
                console.log('lineArray', lineArray);
                console.log('lineHash', lineHash);
                console.log('lineArrayLength', lineArrayLength);

                if (lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) :
                    (lineHash[line] !== undefined)) {
                    //chars += String.fromCharCode(lineHash[line]);
                    chars += String.fromCodePoint(lineHash[line]);
        ...