Skip to content

Instantly share code, notes, and snippets.

View tanmayforgit's full-sized avatar

Tanmay Tupe tanmayforgit

  • Mumbai
View GitHub Profile
@ZhihaoLau
ZhihaoLau / times.js
Created October 14, 2016 02:42
‘Ruby times method’ in JavaScript
// Ruby = 5.times { |i| puts i }
// JS = (1).times(function(i){console.log(i);})
Number.prototype.times = function(cb) {
var i = -1;
while (++i < this) {
cb(i);
}
return +this;