D
Size: a a a
SS
D
Ф
DD
DD
var items = [1, 2, 3, 4, 5, 6];
function isEven(n) {return n % 2 == 0}
var i = partitionOn(isEven, items);
// items should now be [1, 3, 5, 2, 4, 6]
// i should now be 3
DD
DD
var items = [1, 2, 3, 4, 5, 6];
function isEven(n) {return n % 2 == 0}
var i = partitionOn(isEven, items);
// items should now be [1, 3, 5, 2, 4, 6]
// i should now be 3
console.log(i);
console.log(items);
function partitionOn(pred, arr) {
const trueValues = [];
const falseValues = [];
let indexOfFirstTrueItem = 0;
for (let i = 0; i < arr.length; i++) {
if (pred(arr[i]) == true) {
trueValues.push(arr[i]);
} else if (pred(arr[i]) == false) {
falseValues.push(arr[i]);
}
}
for (let k = 0; k < trueValues.length; k++) {
falseValues.push(trueValues[k]);
}
for (let j = 0; j < falseValues.length; j++) {
if (pred(falseValues[j])) {
indexOfFirstTrueItem = j;
break;
}
}
arr = [...falseValues];
return indexOfFirstTrueItem;
}
DD
M
MS
C
document.querySelector('div[attrb] *= value')
вроде такv
const partition = (ary, callback) =>
ary.reduce((acc, e) => {
acc[callback(e) ? 0 : 1].push(e)
return acc
}, [[], []])
T
L
A
SS
A
SS