@jrc03c/js-math-tools
Version:
some math tools for JS
29 lines (23 loc) • 572 B
JavaScript
import { assert } from "./assert.mjs"
import { isArray } from "./is-array.mjs"
import { isDataFrame } from "./is-dataframe.mjs"
import { isSeries } from "./is-series.mjs"
function helper(x) {
if (isArray(x)) {
const childShapes = helper(x[0])
return [x.length].concat(childShapes || [])
} else {
return undefined
}
}
function shape(x) {
if (isDataFrame(x) || isSeries(x)) {
return shape(x.values)
}
assert(
isArray(x),
"The `shape` function only works on arrays, Series, and DataFrames!",
)
return helper(x)
}
export { shape }