src/js/xkcd/index.js
function smooth(d, w) {
    let result = [];
    for (let i = 0, l = d.length; i < l; ++i) {
        let mn = Math.max(0, i - 5 * w),
            mx = Math.min(d.length - 1, i + 5 * w),
            s = 0.0;
        result[i] = 0.0;
        for (let j = mn; j < mx; ++j) {
            let wd = Math.exp(-0.5 * (i - j) * (i - j) / w / w);
            result[i] += wd * d[j];
            s += wd;
        }
        result[i] /= s;
    }
    return result;
}
function smooth(d, w) {
    let result = [];
    for (let i = 0, l = d.length; i < l; ++i) {
        let mn = Math.max(0, i - 5 * w),
            mx = Math.min(d.length - 1, i + 5 * w),
            s = 0.0;
        result[i] = 0.0;
        for (let j = mn; j < mx; ++j) {
            let wd = Math.exp(-0.5 * (i - j) * (i - j) / w / w);
            result[i] += wd * d[j];
            s += wd;
        }
        result[i] /= s;
    }
    return result;
}
function smooth ( d , w ) { let result = [ ] ; for ( let i = 0 , l = d . length ; i < l ; ++ i ) { let mn = Math . max ( 0 , i - 5 * w ) , mx = Math . min ( d . length - 1 , i + 5 * w ) , s = 0.0 ; result [ i ] = 0.0 ; for ( let j = mn ; j < mx ; ++ j ) { let wd = Math . exp ( - 0.5 * ( i - j ) * ( i - j ) / w / w ) ; result [ i ] += wd * d [ j ] ; s += wd ; } result [ i ] /= s ; } return result ; }
Smooth some data with a given window size.
Smooth some data with a given window size .