Javascript 如何从数组';s元素?
以这个“str”为例,“ABCDE”它有以下关于订单的组合Javascript 如何从数组';s元素?,javascript,python,arrays,Javascript,Python,Arrays,以这个“str”为例,“ABCDE”它有以下关于订单的组合“AB”、“ABC”、“ABCD”、“ABCDE”、“DE”、“CDE”、“BCDE”、“CD”、“BC”。我试过了 // thi is javascript code const val = 'ABCDE' let array = [] for (i = 0; i < val.length-1; i++) { array.
“AB”、“ABC”、“ABCD”、“ABCDE”、“DE”、“CDE”、“BCDE”、“CD”、“BC”
。我试过了
// thi is javascript code
const val = 'ABCDE'
let array = []
for (i = 0; i < val.length-1; i++) {
array.push(val.slice(i,val.length))
array.push(val.slice(0,i+2))
array.push(val.slice(i,val.length-i))
}
console.log(
array,
array.includes('BC'),
array.includes('CD')
)
// this is the reuslts: ["ABCDE", "AB", "ABCDE", "BCDE", "ABC", "BCD", "CDE", "ABCD", "C", "DE", "ABCDE", ""]
//this reslutes don't have compnations like 'BC' or 'CD'
//这是javascript代码
const val='ABCDE'
让数组=[]
对于(i=0;i
我没有真正得到我需要的结果。请问您对javascript或python有什么想法吗?我认为python
panda
或可能NumPy
库中有这样的东西。您需要两个嵌套的循环作为子字符串
函数getAllSubstring(str){
常量结果=[];
for(设i=0;i。作为控制台包装{max height:100%!important;top:0;}
在python中,一切都很简单
from itertools import combinations
val = 'ABCDE'
print([''.join(l) for i in range(len(x)) for l in combinations(x, i+1)])
请添加全部的完整结果。也许您正在寻找:@NinaScholz no,它没有给出所有的组合。这感觉好像在某种程度上,它必须能够与regex一起使用……这不会产生期望的结果。
在python中,一切都很简单。
当您使用库时,javascript中的任何语言都会变得简单也有这样的库,如果没有,我也可以用纯python创建一个库,您应该使用tow for循环来实现它。@所有您创建的库都会告诉我。我会用这个:)