How to solve the problem that the quantity of, C (MMag1), m is uncertain when javascript is combined?
topic description
I saw that other people mentioned a question and the following answer. I felt very interested, so I adapted the question
.
sources of topics and their own ideas
the title originally looks like this: `var wordList = [
]
[{""}, {""}, {""}, ""],
[{""}, {""}, {""}],
[{""}, {""}, {""}, {""}, ""],
[{""}, {""}, {""}],
[{""}, {""}, {""}]
]; `
what result do you expect?
how to put it all together? peers can"t form one. For example, it"s right to warmly thank the boss for supporting the store (one for each line).
but thank you very much for your support. This is wrong
.
the amount of m to be extracted each time is not certain. For example, mcm 5 means to warmly thank the boss for supporting the store
mumbo 4, that is, to warmly thank the boss for his support
.
:[{""},{""},{""},{""},{""}]
let wordList = [
['', '', ''],
['', '', ''],
['', '', '', ''],
['', '', ''],
['', '', '']
];
let M = 4;
/** @example cross([[1]], [2,3]) // [[1,2], [1,3]] */
let cross = (a1, a2) => a1.reduce((r, s1) => r.concat(a2.map(s2 => [...s1, s2])), []);
//
//let cross = (a1, a2) => [].concat(...a1.map(s1 => a2.map(s2 => [...s1, s2])));
let result = wordList.slice(0, M).reduce(cross, [[]]);
< hr >
//
let wordList=[
{"name":"","id":1},{"name":"","id":2},{"name":"","id":3},
{"name":"","id":1},{"name":"","id":2},{"name":"","id":3},
{"name":"","id":2},{"name":"","id":1},{"name":"","id":1}]
wordList = wordList.reduce((r, o)=>(r[o.id-1]=(r[o.id-1]||[]).concat(o.name),r),[]);
//
import * as _ from 'lodash';
var wordList = [
['', '', ''],
['', '', ''],
['', '', '', ''],
['', '', ''],
['', '', '']
];
var sentence=_.map(wordList,_.sample).join('');
what should I do if I change it like this:
let wordList=[
{"name":"","id":1},{"name":"","id":2},{"name":"","id":3},
{"name":"","id":1},{"name":"","id":2},{"name":"","id":3},
{"name":"","id":2},{"name":"","id":1},{"name":"","id"1}
]
the same id cannot be combined into a group, and how many combinations there are? similarly, M is uncertain. Choose M from these groups and how to code
.