lundi 16 novembre 2020

How to combine strings in ordered arrays to build sentences [duplicate]

Let say I have 4 arrays of strings with different lengths in Javascript like the following:

const a1 = ['A', 'The', 'This', 'That'];
const a2 = ['vehicle', 'auto', 'car'];
const a3 = ['looks', 'appears', 'seems to be'];
const a4 = ['beautiful', 'good', 'pretty',  'awesome'];

And my issue is to build most possible sentences by combining the words in each array with the next one. At the end, I would have an array of sentences like this:

const sentences = [
   'A vehicle looks beautiful',
   'A vehicle looks good',
   'A vehicle looks pretty',
   'A vehicle looks awesome',
   'A vehicle appears beautiful',
   'A vehicle appears good',
   'A vehicle appears pretty',
   'A vehicle appears awesome',
   'A vehicle seems to be awesome',
   ...,
   'That car seems to be beautiful'
];

So how can I achieve that result ?




Aucun commentaire:

Enregistrer un commentaire