Skip to content

Instantly share code, notes, and snippets.

@martinaglv
Last active August 29, 2015 14:04
Show Gist options
  • Save martinaglv/3511674068491ef0161f to your computer and use it in GitHub Desktop.
Save martinaglv/3511674068491ef0161f to your computer and use it in GitHub Desktop.
Sparklines
#!/usr/bin/env node
var ticks = '▁▂▃▄▅▆▇'.split(''),
values = process.argv.slice(2);
var min = Math.min.apply(0, values),
range = Math.max.apply(0, values) - min,
scale = ticks.length - 1;
console.log( values.map(function(x){
return ticks[ Math.round(((x - min) / range) * scale) ];
}).join('') );
./spark.js 3 20 1 8 12 9 40
▁▄▁▂▃▂▇
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment