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?
I am not sure if this is exactly what you are looking for but I think it might look something like:
Maybe you forgot the
returnkeyword in yourmySumfunction.