/**
*
* Ashish Patel
* e: ashishsushilPatel@gmail.com
* w: https://ashish.me
*
*/
/* 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*",
"*****"]
*/
function addBorder(values) {
const wall = '*'.repeat(values[0].length+2)
values = values.map((str) => `*${str}*`)
values.push(wall)
values.unshift(wall)
return values
}
test('add Border', () => {
expect(addBorder(['abc', 'ded'])).toEqual(['*****', '*abc*', '*ded*', '*****'])
})
Created 2019-12-05T02:47:16+05:30 · Edit