D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
st44100
Full window
Github gist
// source http://jsbin.com/dumude
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JS Bin</title> </head> <body> <script id="jsbin-javascript"> var a, b, padItems; padItems = function(items, size, pad) { var i, _i, _ref; if (size == null) { size = 3; } if (pad == null) { pad = {}; } if (!(items.length < size)) { return items.slice(0, size); } for (i = _i = _ref = items.length; _ref <= size ? _i < size : _i > size; i = _ref <= size ? ++_i : --_i) { items[i] = null; } return items; }; a = [1, 2]; console.log(padItems(a, 10)); b = [1, 2, 3, 4, 5]; console.log(padItems(b, 2)); </script> <script id="jsbin-source-javascript" type="text/javascript">padItems = (items, size = 3, pad = {}) -> unless items.length < size return items[0...size] items[i] = null for i in [items.length...size] return items a = [1, 2] console.log padItems(a, 10) b = [1, 2, 3, 4, 5] console.log padItems(b, 2)</script></body> </html>