Say I have some cats:
interface Cat {
name: string
age: number
color: string
}
I want to sum the ages of cats of each color. This works as expected in (Ala)SQL:
const sql = `
SELECT name, sum(age)
FROM ?
GROUP BY color
`
alasql(sql, [cats])
But if I write a user-defined sum instead:
import {sum} from 'lodash'
alasql.fn.mySum = function(xs) { sum(xs) }
const sql = `
SELECT name, mySum(age)
FROM ?
GROUP BY color
`
alasql(sql, [cats])
then mySum
is called with xs
equal to undefined
. What am I doing wrong here?