Closed lucas-pollus closed 3 years ago
import { from } from "linq-to-typescript"
interface ICustomer {
name: string
priceUnit: number
quantity: number
}
const customers: ICustomer[] = [
{ name: "Brian", priceUnit: 10, quantity: 1 },
{ name: "John", priceUnit: 10, quantity: 2 },
{ name: "Brian", priceUnit: 10, quantity: 3 }
]
const list = from(customers)
.select(c => {
return { name: c.name, total: c.priceUnit * c.quantity }
})
.groupBy(({name}) => name)
.select(group => {
const total = group.sum(s => s.total)
return { name: group.key, total }
})
.toArray()
for (const { name, total } of list) {
console.log(`Name: ${name}, Total: ${total}`)
}
@arogozine thanks!!!
Hello,
In c# I have the following code:
I tried to reproduce this using LinqToTypeScript but I couldn't. Can you help me?