How to use the simple-statistics.average function in simple-statistics

To help you get started, we’ve selected a few simple-statistics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github electron / i18n / script / wordcount.ts View on Github external
.map(file => matchWords(fs.readFileSync(file, 'utf8')))
    .flatten()
    .value()
  const counts = files.map(
    f => (matchWords(fs.readFileSync(f, 'utf8')) || []).length
  )
  const { average, sum } = require('simple-statistics')

  const results: Record = {
    'total files': files.length,
    'total words': sum(counts),
    'unique words': chain(words)
      .flatten()
      .uniq()
      .value().length,
    'average words per file': Math.floor(average(counts)),
  }

  console.log(`\n## ${title}\n`)
  console.log('Stat | Value')
  console.log('---- | -----')

  Object.keys(results).forEach(stat => {
    console.log([stat, results[stat]].join(' | '))
  })
}
github Turfjs / turf / lib / average.js View on Github external
_.each(polyFC.features, function(poly){
    if(!poly.properties){
      poly.properties = {}
    }
    var values = []
    _.each(ptFC.features, function(pt){
      t.inside(pt, poly, function(err, isInside){
        if(isInside){
          values.push(pt.properties[inField])
        }
      })
    })
    poly.properties[outField] = ss.average(values)
  })