als-statistics
Version:
A powerful and lightweight JavaScript library for descriptive statistics, regression, clustering, outlier detection, and noise analysis using a flexible table/column architecture.
20 lines (17 loc) • 577 B
JavaScript
const newColumn = require('../utils/new-column')
function extractMetric(col, metricName) {
const keys = metricName.split('.')
let value = col;
for (let i = 0; i < keys.length; i++) {
if (value === undefined) break;
value = value[keys[i]];
if (Array.isArray(value) && value.length) value = newColumn(value)
}
return value;
}
function extractMetrics(columns,metricName) {
return Object.values(columns)
.map(col => extractMetric(col, metricName))
.filter(v => v !== undefined)
}
module.exports = extractMetrics