TypeScript · Playground
TypeScript playground
Transpiled by the TypeScript compiler in your browser (types are erased, not checked) and then run exactly like JavaScript. Read input with readline() / readAll(); print with console.log.
interface Item { name: string; qty: number }
const items: Item[] = [{ name: "tea", qty: 3 }, { name: "rice", qty: 2 }];
const total: number = items.reduce((s, i) => s + i.qty, 0);
console.log(`${items.length} items, ${total} units`);
Output
Press Run to see the program’s output here.
Transpiled by the TypeScript compiler in your browser (types are erased, not checked) and then run exactly like JavaScript. Read input with readline() / readAll(); print with console.log.
Your code runs in your browser. TypeScript is transpiled to JavaScript before execution; no code is sent to a server.