Nodejs Function Call times(func)

Here you can find the source of times(func)

Method Source Code

// http://www.codewars.com/kata/ruplesjs-number-1-n-times-do


var i = 0;//w w w .jav  a 2 s  .  co m

Number.prototype.times = function(func) {
  let n = Math.round(this);  
  if (n <= 0) return null;
  
  func();
  return (n - 1).times(func);
}

console.log(i);

Related

  1. map(map)
    Function.prototype.map = function (map) {
        var params = this.getParamNames();
        var fn = this;
        for (var i in params)
            fn = fn.bind({}, map[params[i]]);
        return fn;
    };
    
  2. times(f, context)
    Number.prototype.times = function(f, context){
      var n = Number(this);
      for(var i = 0; i < n; i++){
        f.call(context, i);
    };
    
  3. times(f, context)
    function Range(from, to) {
        this.from = from;
        this.to = to;
    };
    Range.prototype = {
        constructor: Range,
        includes: function(x) {
            return this.from <= x && x <= this.to;
        },
    ...
    
  4. times(f, context)
    Number.prototype.times = function(f, context) {
      var n = Number(this);
      for(var i = 0; i < n; i++) f.call(context, i);
    };
    String.prototype.trim = String.prototype.trim || function() {
      if (!this) return this; 
      return this.replace(/^\s+|\s+$/g, ""); 
    };
    Function.prototype.getName = function() {
    ...
    
  5. times(fn)
    'use strict';
    Number.prototype.times = function(fn) {
      if (this.valueOf()) {
        for (var i = 0; i < this.valueOf(); i++) {
          fn(i);
    };
    function repeat(n, fn) {
    ...
    
  6. times(func)
    Number.prototype.times = function (func) {
      var i;
      for (i = 0; i < this; i += 1) {
        func();
    };
    function random(min, max) {
        var floor = +min,
            ceil = +max;
    ...
    
  7. times(func, scope)
    Number.prototype.times = function(func, scope) {
      var i, v, _results;
      v = this.valueOf();
      i = 0;
      _results = [];
      while (i < v) {
        func.call(scope || window, i);
        _results.push(i++);
      return _results;
    };
    
  8. times(handler)
    Number.prototype.times = function(handler) {
      var index = 0;
      while(index < this) handler(index++);
      return this
    };
    
  9. times(iterator)
    Number.prototype.times = function(iterator) {
      var index = 0;
      while(index < this) iterator(index++);
      return this
    };