code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

06 Repeat String

/**
 * Created by Ashish Patel
 * Copyright © 2017 ashish.me
 * ashishsushilpatel@gmail.com 
 */

/**
 * Repeat a given string (first argument) num times (second argument). 
 * Return an empty string if num is not a positive number.
 */

 
function repeatStringNumTimes(str, num) {
    let fullString = "";
    while (num > 0){
        fullString += str;
        num--;
    }
    return fullString;
  }
  
console.log(repeatStringNumTimes("*", 8));

Created 2019-11-24T04:41:20+05:18 · Edit