sliptAt array
by philll_t
JavaScript
const splitAt = (arr, condition, index_only) => {
const index = arr.findIndex(condition);
let left = [];
let right = [];
if (index < 0) {
return [[], []];
}
if (index_only) {
arr.forEach((el, i) => {
if (i < index) {
left.push(i);
} else {
right.push(i);
}
})
} else {
console.log(index);
right = arr.slice(index);
left = arr.slice(0, index);
}
return [left, right];
}
const test_array = [1, 2, 3, 4, 5, 6, 7];
const con = (x) => x > 4;
console.log(splitAt(test_array, con, true));