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)))
result:
["
*****
*cat*
*****
",
"
*******
*a dog*
*******
"]
Top comments (0)