html/rainbow/rainbow.js
function _processReplacements(code, onComplete) {

        /**
         * processes a single replacement
         *
         * @param {string} code
         * @param {Array} positions
         * @param {number} i
         * @param {Function} onComplete
         * @returns void
         */
        function _processReplacement(code, positions, i, onComplete) {
            if (i < positions.length) {
                ++replacement_counter;
                var pos = positions[i],
                    replacement = replacements[CURRENT_LEVEL][pos];
                code = _replaceAtPosition(pos, replacement['replace'], replacement['with'], code);

                // process next function
                var next = function() {
                    _processReplacement(code, positions, ++i, onComplete);
                };

                // use a timeout every 250 to not freeze up the UI
                return replacement_counter % 250 > 0 ? next() : setTimeout(next, 0);
            }

            onComplete(code);
        }

        var string_positions = keys(replacements[CURRENT_LEVEL]);
        _processReplacement(code, string_positions, 0, onComplete);
    }
function _processReplacements(code, onComplete) {

        /**
         * processes a single replacement
         *
         * @param {string} code
         * @param {Array} positions
         * @param {number} i
         * @param {Function} onComplete
         * @returns void
         */
        function _processReplacement(code, positions, i, onComplete) {
            if (i < positions.length) {
                ++replacement_counter;
                var pos = positions[i],
                    replacement = replacements[CURRENT_LEVEL][pos];
                code = _replaceAtPosition(pos, replacement['replace'], replacement['with'], code);

                // process next function
                var next = function() {
                    _processReplacement(code, positions, ++i, onComplete);
                };

                // use a timeout every 250 to not freeze up the UI
                return replacement_counter % 250 > 0 ? next() : setTimeout(next, 0);
            }

            onComplete(code);
        }

        var string_positions = keys(replacements[CURRENT_LEVEL]);
        _processReplacement(code, string_positions, 0, onComplete);
    }
function _processReplacements ( code , onComplete ) { /**
         * processes a single replacement
         *
         * @param {string} code
         * @param {Array} positions
         * @param {number} i
         * @param {Function} onComplete
         * @returns void
         */ function _processReplacement ( code , positions , i , onComplete ) { if ( i < positions . length ) { ++ replacement_counter ; var pos = positions [ i ] , replacement = replacements [ CURRENT_LEVEL ] [ pos ] ; code = _replaceAtPosition ( pos , replacement [ 'replace' ] , replacement [ 'with' ] , code ) ; // process next function var next = function ( ) { _processReplacement ( code , positions , ++ i , onComplete ) ; } ; // use a timeout every 250 to not freeze up the UI return replacement_counter % 250 > 0 ? next ( ) : setTimeout ( next , 0 ) ; } onComplete ( code ) ; } var string_positions = keys ( replacements [ CURRENT_LEVEL ] ) ; _processReplacement ( code , string_positions , 0 , onComplete ) ; }
process replacements in the string of code to actually update the markup

@param {string} code         the code to process replacements in
@param {Function} onComplete   what to do when we are done processing
@returns void
process replacements in the string of code to actually update the markup