Skip to content

Instantly share code, notes, and snippets.

@husen-hn
Created November 22, 2022 07:42
Show Gist options
  • Save husen-hn/1f1ce4ad99ec998b9446ca933ed1d796 to your computer and use it in GitHub Desktop.
Save husen-hn/1f1ce4ad99ec998b9446ca933ed1d796 to your computer and use it in GitHub Desktop.
const cartItem = [
{
title: 'Book1',
exist: false
}, {
title: 'Book2',
exist: true
}, {
title: 'Book3',
exist: true
}, {
title: 'Book4',
exist: false
},
]
function sortProcusts(carts) {
carts.sort(function(a, b) {
if(a.exist === true && b.exist === false){
return -1
} else if(a.exist === false && b.exist === true) {
return 1
} else {
return 0
}
})
}
sortProcusts(cartItem)
console.log(cartItem)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment