I have an array that needs to be filtered with specific condition
**Input**
let arr=[
"abcde-backup",
"abcde",
"fghij-backup",
"fghij",
"klmnop-backup",
"qrstuv"
]
I am trying to achieve output like this
**output**
[
"abcde-backup",
"fghij-backup",
"klmnop-backup",
"qrstuv"
]
If any value has -backup has suffix then it should take that and it should avoid the one without backup . Here
fghij-backuphas value with backup so that is the priority.If the value doesnt have backup has suffix then it should take it has priority
eg:qrstuv
I am struck with the second point . I have tried with this code
function getLatestJobId(){
let finalArr=[];
arr.forEach(val=>{
if(val.indexOf('-backup') > -1){
finalArr.push(val);
}
})
return finalArr;
}