拿這個“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庫有這樣的東西。
如何從數組的元素中獲取不同的組合?
慕姐8265434
2023-12-14 16:34:53