I am also able to filter for distinct values.
But I can’t figure out how to combine this information to count the appearance of each “food” to get some thing like this:
// FSL
collection Order {
// other schema...
index by_user__date_desc_food_asc {
terms [.user]
values [.date, .food] // same values as the v4 index
}
}
thanks for your reply.
I am able to do it locally, sure. I just wanted to do/try it in FQL for “educational” purpose.
I’ve already looked at the fold() function and other options.
But I can’t figure out the right synthax.
Variables in FQL are immutable, but you can create new objects with dynamic keys and altered values using Object.assign function and the Object.fromEntries function, both of which work like the equivalent functions in JS.
let arr = ['b', 'a', 'c', 'b', 'b', 'a'];
let count = arr.fold({}, (accumulator, value) => {
let count = (accumulator[value] ?? 0) + 1
let override = Object.fromEntries([[value, count]])
Object.assign(accumulator, override)
});