I'm working on a project using Angular2, and I have a collection of parties.
const PARTIES: Party[] = [
{ id: 1, title: "Main Event", description: "The biggest, most extravagant event in the last 10,000,000 years." },
{ id: 2, title: "Secondary Event", description: "The not as biggest, less extravagant event in the last 10,000,000 years." },
{ id: 3, title: "Another Event", description: "N/A" },
{ id: 4, title: "Another Event", description: "N/A" },
{ id: 5, title: "Another Event", description: "N/A" },
{ id: 6, title: "Another Event", description: "N/A" },
{ id: 7, title: "Another Event", description: "N/A" },
{ id: 8, title: "Another Event", description: "N/A" },
{ id: 9, title: "Another Event", description: "N/A" },
{ id: 10, title: "Another Event", description: "N/A" }
];
I want to divide this array into groups of 3 while keeping the original intact.
In regular JavaScript, I would do something like this:
var chunk_size = 3;
var arr = PARTIES;
var groups = arr.map(function(e,i){
return i%chunk_size===0 ? arr.slice(i,i+chunk_size) : null;
})
.filter(function(e){ return e; });
PARTIES = groups
However, I am using TypeScript. Is it possible to achieve the same segmentation using TypeScript?