Created
January 9, 2015 13:40
-
-
Save st44100/a335c0802dbc6aca6296 to your computer and use it in GitHub Desktop.
// source http://jsbin.com/dumude
This file contains hidden or 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> | |
<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> |
This file contains hidden or 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
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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment