Javascript String times(times)
'use strict'/*from w w w. j ava 2s .co m*/ // Times method exercise String.prototype.times = function(times) { return this.repeat(times); }; console.log('*'.times(10)); // OOP let menu = require('./menu'); menu();
// ES6 comes with String.prototype.repeat() String.prototype.times = function(times) { var string = this.toString(), result = ''; for(i = 0; i < times; i++) { result += string;/* www . j a va2 s.c o m*/ } return result; };
String.prototype.times = function(times) { var string = this; for (var i = 1; i < times; i++) { string += this;/*from ww w . ja va 2 s .c o m*/ } return string; };
'use strict'// w w w .j a v a 2s . c om // Times method exercise String.prototype.times = function(times) { return this.repeat(times); }; console.log('*'.times(10));