Add Border

Description


Given a rectangular matrix of characters, add a border of asterisks(*) to it.

Example

For

picture = ["abc", "ded"]

the output should be

addBorder(picture) = ["*****", "*abc*", "*ded*", "*****"]

Input/Output

  • [execution time limit] 4 seconds (js)

  • [input] array.string picture

A non-empty array of non-empty equal-length strings.

Guaranteed constraints: 1 ≤ picture.length ≤ 100, 1 ≤ picture[i].length ≤ 100.

  • [output] array.string

The same matrix of characters, framed with a border of asterisks of width 1.

[JavaScript (ES6)] Syntax Tips

1
2
3
4
5
6
// Prints help message to the console
// Returns a string
function helloWorld(name) {
    console.log("This prints to the console when you Run Tests");
    return "Hello, " + name;
}

Solution


1
2
3
4
5
6
7
function addBorder(picture) {
    picture = picture.map(f=>'*'.concat(f,'*'))
    var l = picture[0].length;
    picture.unshift(Array(l).fill('*').join(''));
    picture.push(Array(l).fill('*').join(''))
    return picture;
}