I have an array of objects which looks like this:
[
{
pVerb: "ask somebody out",
meaning: "invite on a date"
},
{
pVerb: "ask around",
meaning: "ask many people the same question"
},
{
pVerb: "add up to something",
meaning: "equal"
},
{
pVerb: "back something up",
meaning: "reverse"
},
{
pVerb: "back somebody up",
meaning: "support"
},
{
pVerb: "blow up",
meaning: "explode"
}
]
I need to iterate trough every object and generate smaller array chunks that should:
- Be of a length of 3
- Contain current object entry of pVerb
- Be placed on random positions
something like following:
[
[
"!ask somebody out!",
"add up to something",
"back something up"
],
[
"add up to something",
"!ask around!",
"blow up"
],
[
"blow up",
"back somebody up",
"!add up to something!"
]
]
Currently I have something like this but it does not check for duplicate entries or randomize the positions:
const randomNumber = (max: number, min: number) => {
const num = Math.floor(Math.random() * (max - min + 1)) + min;
return num;
};
const array: any[] = [];
for (const n of array) {
array.push([
n.meaning,
array[randomNumber(0, array.length)]
.meaning,
array[randomNumber(0, array.length)]
.meaning
]);
}
TL:DR
I need array of chunks where a chunk would be [pVerb of first object, any other two pVerbs from any other two objects(unique)]
next chunk would have [pVerb of second object, ...]
etc.