DEV Community

Miguel Ramirez
Miguel Ramirez

Posted on • Edited on

javascript - wrappin gifts using *

const giftList = ["cat", "a dog"]
function wrap(str){
  const strNumber = str.length
  let layer = "**"
  let counter = 0
  while (counter < strNumber) {
    layer = layer.concat("*")
    counter = counter + 1;
  } 
  str =  "*".concat(str.concat("*"))
  return layer.concat("\n", str, "\n", layer)
}

console.log(giftList .map(gift => wrap(gift)))
Enter fullscreen mode Exit fullscreen mode

result:

["
*****
*cat*
*****
", 

"
*******
*a dog*
*******
"]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)