Answer the question
In order to leave comments, you need to log in
How to split text without repetition?
We need a function that parses the text into all combinations without repetition
. For example, like this
1) the boat swam swam and drowned
2) the boat swam swam and
3) swam swam and drowned
4) the boat swam swam
5) swam and drowned
6) the boat swam
7) swam swam
8) swam and
9) and drowned
10) boat
11) swam
12) and
13) drowned
Maybe I even missed it, I don’t know for sure
Answer the question
In order to leave comments, you need to log in
var start = ('кораблик плавал плавал и утонул').split(' ');
for (var i = 0, result = [], _result = {}, stroke; i <= start.length; i++) {
for (var j = 0; j < i; j++) {
stroke = start.slice(j, j + start.length - i + 1).join(' ');
if (!_result[stroke]) {
_result[stroke] = result.push(stroke);
}
}
}
console.log(result);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question