Built with blockbuilder.org
Last active
February 8, 2016 18:40
-
-
Save biovisualize/6e089db6771df328d223 to your computer and use it in GitHub Desktop.
Selection sort
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
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
<style> | |
div{ | |
width: 50px; | |
height: 50px; | |
} | |
</style> | |
</head> | |
<body> | |
<script> | |
var divs = d3.select('body').selectAll('div') | |
.data([ | |
{foo: 1, bar: 3, color: 'red'}, | |
{foo: 2, bar: 2, color: 'blue'}, | |
{foo: 3, bar: 1, color: 'green'} | |
]) | |
.enter().append('div') | |
.style({ | |
'background-color': function(d){ return d.color; } | |
}); | |
divs.sort(function(a, b){ var sortKey = 'foo'; return a[sortKey] - b[sortKey]; }); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment