JSFiddle - React, Tailwind, and code Playground
by joplomacedo
JavaScript
const prevBars=['b1', 'b2', 'b3'];
const newBars=['b1', 'b2', 'b3', 'b4', 'b5'];
function findLastIndex(arr, predicate = () => false ) {
let l = arr.length;
while (l--) {
if ( predicate(arr[l], l, arr) ) {
return l;
}
}
return -1;
};
const idx = findLastIndex( newBars, item => item == 'b2' );
console.log(idx);
console.log('common:', newBars.slice(0, idx+1))
console.log('new:', newBars.slice(idx+1))