【发布时间】:2017-08-06 13:12:16
【问题描述】:
我正在尝试在 JavaScript 中创建一个函数,该函数对于给定的字符串将通过删除输出所有可能的组合 每次只有字符串中的 4 个字符。我怎样才能输出所有的组合?起始字符串的长度是动态的。提前谢谢。
**注意:**删除4个字符的顺序不应该总是连续的
例子:
string:BmamdWRtaW51dGfVzZMI= //B m a m d W R t a W 5 1 d G f V z Z M I =
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
想要像这样打印所有可能的组合:
BmamdWRtaW51dGfVzZMI= (starting string)
-dWRtaW51dGfVzZMI= (removed first 4 characters)
-BWRtaW51dGfVzZMI= (removed 4 consecutive charaters start from 2th character)
-BmRtaW51dGfVzZMI= (removed 4 consecutive charaters start from 3th character)
-BmataW51dGfVzZMI= (removed 4 consecutive charaters start from 4th character)
-
-
【问题讨论】:
-
到目前为止,您是否尝试过任何特定的方法?
-
这4个字符总是连续的吗?
-
感谢您的回复。 @Jean-Claude Colette 4 个字符不应该总是连续的,我想打印出所有可能的组合。
-
@Jonas w.感谢您的回复。字符串内容和大小是动态的,但我每次只能删除 4 个字符。字符串上的字符没有任何顺序!
标签: javascript jquery string combinations