Created
November 22, 2022 07:42
-
-
Save husen-hn/1f1ce4ad99ec998b9446ca933ed1d796 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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