Skip to content

Instantly share code, notes, and snippets.

@Kotrotsos
Last active April 12, 2023 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kotrotsos/20445bf6e67009f3c045e52636de6264 to your computer and use it in GitHub Desktop.
Save Kotrotsos/20445bf6e67009f3c045e52636de6264 to your computer and use it in GitHub Desktop.
// Making Javascript more like Ruby is fun. :)
// Times
Number.prototype.times = function(callback) {
for (var i = 1; i <= this.valueOf(); i++) {
callback();
}
}
3..times(function() {
console.log("Hello");
});
(3).times(function() {
console.log("Hello");
});
// Unless
const unless = (condition, callback) => {
if (!condition) {
callback();
}
};
let x = 5;
unless (x === 4, () => {
console.log("x is not 4");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment