demo/editor/kissy.js
function (arr, callback, initialValue) {
            var len = arr.length;
            if (typeof callback !== 'function') {
                throw new TypeError('callback is not function!');
            }

            // no value to return if no initial value and an empty array
            if (len === 0 && arguments.length == 2) {
                throw new TypeError('arguments invalid');
            }

            var k = 0;
            var accumulator;
            if (arguments.length >= 3) {
                accumulator = arguments[2];
            }
            else {
                do {
                    if (k in arr) {
                        accumulator = arr[k++];
                        break;
                    }

                    // if array contains no values, no initial value to return
                    k += 1;
                    if (k >= len) {
                        throw new TypeError();
                    }
                }
                while (TRUE);
            }

            while (k < len) {
                if (k in arr) {
                    accumulator = callback.call(undefined, accumulator, arr[k], k, arr);
                }
                k++;
            }

            return accumulator;
        }
function (arr, callback, initialValue) {
            var len = arr.length;
            if (typeof callback !== 'function') {
                throw new TypeError('callback is not function!');
            }

            // no value to return if no initial value and an empty array
            if (len === 0 && arguments.length == 2) {
                throw new TypeError('arguments invalid');
            }

            var k = 0;
            var accumulator;
            if (arguments.length >= 3) {
                accumulator = arguments[2];
            }
            else {
                do {
                    if (k in arr) {
                        accumulator = arr[k++];
                        break;
                    }

                    // if array contains no values, no initial value to return
                    k += 1;
                    if (k >= len) {
                        throw new TypeError();
                    }
                }
                while (TRUE);
            }

            while (k < len) {
                if (k in arr) {
                    accumulator = callback.call(undefined, accumulator, arr[k], k, arr);
                }
                k++;
            }

            return accumulator;
        }
function ( arr , callback , initialValue ) { var len = arr . length ; if ( typeof callback !== 'function' ) { throw new TypeError ( 'callback is not function!' ) ; } // no value to return if no initial value and an empty array if ( len === 0 && arguments . length == 2 ) { throw new TypeError ( 'arguments invalid' ) ; } var k = 0 ; var accumulator ; if ( arguments . length >= 3 ) { accumulator = arguments [ 2 ] ; } else { do { if ( k in arr ) { accumulator = arr [ k ++ ] ; break ; } // if array contains no values, no initial value to return k += 1 ; if ( k >= len ) { throw new TypeError ( ) ; } } while ( TRUE ) ; } while ( k < len ) { if ( k in arr ) { accumulator = callback . call ( undefined , accumulator , arr [ k ] , k , arr ) ; } k ++ ; } return accumulator ; }
Executes the supplied function on each item in the array.
Returns a value which is accumulation of the value that the supplied
function returned.

@param arr {Array} the array to iterate
@param callback {Function} the function to execute on each item
@param initialValue {number} optional context object
refer: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/reduce
@return {Array} The items on which the supplied function returned
@member KISSY
Executes the supplied function on each item in the array . Returns a value which is accumulation of the value that the supplied function returned .