我需要在最多5个字符的输入中显示输入值的所有排列
我制作了这个Codepen示例,但效果不佳
https://codepen.io/alonsoct00/pen/WBeXEp
我的脚本:
if adb -s emulator-5554 uninstall my.package ; then
echo "The command succeeded, yay!"
else
code="$?"
echo "The command failed with exit code $code"
fi
谢谢
答案 0 :(得分:1)
尝试使用传播算子:
document.getElementById('results').innerHTML = (permute([...txtval]).join("\n"));
不确定这是否是您要查找的确切输出
https://codepen.io/jfitzsimmons/pen/RmNZGP
此外,我喜欢以下代码进行排列:
const permutations = arr => {
if (arr.length <= 2) return arr.length === 2 ? [arr, [arr[1], arr[0]]] : arr;
return arr.reduce(
(acc, item, i) =>
acc.concat(
permutations([...arr.slice(0, i), ...arr.slice(i + 1)]).map(val => [item, ...val])
),
[]
);
};
EXAMPLES
permutations([1, 33, 5]); // [ [ 1, 33, 5 ], [ 1, 5, 33 ], [ 33, 1, 5 ], [ 33, 5, 1 ], [ 5, 1, 33 ], [ 5, 33, 1 ] ]
答案 1 :(得分:1)
您要用新内容替换innerHTML。
Map<Object,Long> mp = pojoList.stream().collect(Collectors.groupingBy(p -> p.sport,Collectors.counting()));
应该可以解决问题。在这里使用Array.prototype.join()毫无意义,new PojoOutput("Football","M",1000)
new PojoOutput("Cricket","F",1000)
new PojoOutput("Cricket","M",500)
将无法以您想要的HTML方式工作。
这也是显示内容最复杂的方法 为什么不只是获取原始输入并进行解析?