export const getElementsAfterSecondOccurrence = ( arr, column, targetValue ) => {
let count = 0 ;
let secondIndex = - 1 ;
for ( let i = 0 ; i < arr. length; i++ ) {
if ( arr[ i] [ column] === targetValue) {
count++ ;
if ( count === 2 ) {
secondIndex = i;
break ;
}
}
}
if ( secondIndex !== - 1 ) {
return [ secondIndex, arr. slice ( secondIndex) ] ;
} else {
return [ ] ;
}
} ;
const secondEle = getElementsAfterSecondOccurrence ( dealData, 'groupCode' , 'A1' ) ;
secondEle[ 1 ] ?. forEach ( ( element ) => {
element. groupCode = 'B' + element. groupCode. slice ( 1 , element. groupCode. length) ;
} ) ;
let secondEleCopy = cloneDeep ( secondEle[ 1 ] ) ;
let thirdEle = [ ] ;
if ( secondEleCopy) {
thirdEle = getElementsAfterSecondOccurrence ( secondEleCopy, 'groupCode' , 'B1' ) ;
thirdEle[ 1 ] ?. forEach ( ( element ) => {
element. groupCode = 'C' + element. groupCode. slice ( 1 , element. groupCode. length) ;
} ) ;
}
if ( thirdEle[ 1 ] ?. length > 0 ) {
dealChildVal = [ ... dealData. slice ( 0 , secondEle[ 0 ] ) , ... secondEle[ 1 ] . slice ( 0 , thirdEle[ 0 ] ) , ... thirdEle[ 1 ] ] ;
} else if ( thirdEle[ 1 ] ?. length == 0 && secondEle[ 0 ] ) {
dealChildVal = [ ... dealData. slice ( 0 , secondEle[ 0 ] ) , ... secondEleCopy] ;
} else {
dealChildVal = dealData;
}