Skip to content

Instantly share code, notes, and snippets.

@HACK21 HACK21/index.html forked from anonymous/index.html
Created Sep 21, 2016

Embed
What would you like to do?
JS Bin [美团面试两列排序] // source https://jsbin.com/mejapis
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="[美团面试两列排序]">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
var arr = [
{price:18, rank:5},
{price:8, rank:4},
{price:12, rank:2},
{price:12, rank:4},
{price:8, rank:3},
{price:15, rank:5},
{price:20, rank:4},
{price:9, rank:1}
]
var res = arr.sort(function(a,b){
return a.price != b.price ? a.price - b.price : b.rank - a.rank;
})
console.log(arr);
</script>
<script id="jsbin-source-javascript" type="text/javascript">var arr = [
{price:18, rank:5},
{price:8, rank:4},
{price:12, rank:2},
{price:12, rank:4},
{price:8, rank:3},
{price:15, rank:5},
{price:20, rank:4},
{price:9, rank:1}
]
var res = arr.sort(function(a,b){
return a.price != b.price ? a.price - b.price : b.rank - a.rank;
})
console.log(arr);</script></body>
</html>
var arr = [
{price:18, rank:5},
{price:8, rank:4},
{price:12, rank:2},
{price:12, rank:4},
{price:8, rank:3},
{price:15, rank:5},
{price:20, rank:4},
{price:9, rank:1}
]
var res = arr.sort(function(a,b){
return a.price != b.price ? a.price - b.price : b.rank - a.rank;
})
console.log(arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.