拿这个“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.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 或 python 有什么想法吗?我认为 pythonpanda或可能NumPy库有这样的东西。
繁星coding
慕哥6287543
相关分类