Skip to content

Instantly share code, notes, and snippets.

Created December 5, 2016 12:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4eec3ea97b000bda3ba2b2486af66bb4 to your computer and use it in GitHub Desktop.
Save anonymous/4eec3ea97b000bda3ba2b2486af66bb4 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/wesisamuzu
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
var data = [
{ count: 'phone', year: '1956' },
{ count: 'phone', year: '1971' },
{ count: 'text', year: '1989' },
{ count: '33', year: '1932' },
{ count: '33', year: '1912' },
{ count: 'text', year: '1954' },
{ count: 'phone', year: '1920' },
{ count: '33', year: '3444' }
];
data.sort(function(a,b){
return a['count']<b['count']?-1:(a['count']>b['count']?1:(a['year']<b['year']?-1:1));
});
var i;
for (i = 0; i < data.length; i++) {
document.write("<p>count:" + data[i].count +
" year:" + data[i].year + "</p>");
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">var data = [
{ count: 'phone', year: '1956' },
{ count: 'phone', year: '1971' },
{ count: 'text', year: '1989' },
{ count: '33', year: '1932' },
{ count: '33', year: '1912' },
{ count: 'text', year: '1954' },
{ count: 'phone', year: '1920' },
{ count: '33', year: '3444' }
];
data.sort(function(a,b){
return a['count']<b['count']?-1:(a['count']>b['count']?1:(a['year']<b['year']?-1:1));
});
var i;
for (i = 0; i < data.length; i++) {
document.write("<p>count:" + data[i].count +
" year:" + data[i].year + "</p>");
}
</script></body>
</html>
var data = [
{ count: 'phone', year: '1956' },
{ count: 'phone', year: '1971' },
{ count: 'text', year: '1989' },
{ count: '33', year: '1932' },
{ count: '33', year: '1912' },
{ count: 'text', year: '1954' },
{ count: 'phone', year: '1920' },
{ count: '33', year: '3444' }
];
data.sort(function(a,b){
return a['count']<b['count']?-1:(a['count']>b['count']?1:(a['year']<b['year']?-1:1));
});
var i;
for (i = 0; i < data.length; i++) {
document.write("<p>count:" + data[i].count +
" year:" + data[i].year + "</p>");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment