string dibagi menjadi tiga kombinasi non kosong JS
const string = "abcd";
const array = string.split("");
const output = array.reduce((carry, _, idx, arr) => {
if (idx < arr.length - 1) {
const str = arr[idx] + arr[idx + 1];
const subArray = [...arr];
subArray.splice(idx, 2, str);
carry.push(subArray);
}
return carry;
}, []);
console.log(output);
Run code snippet
Shy Seal