JSFiddle - React, Tailwind, and code Playground

by Prathameshsb

TypeScript

function addBorder(picture: string[]): string[] {
    // Calculate the length of the new strings (original length + 2 for the asterisks)
    const length = picture[0].length + 2;
    
    // Create the top and bottom borders
    const border = '*'.repeat(length);
    
    // Map each string in the array to a new string enclosed in asterisks
    const framedPicture = picture.map(line => `*${line}*`);
    
    // Add the border to the top and bottom of the picture
    return [border, ...framedPicture, border];
}

// Test the function with the provided example
const picture = ["abc", "ded"];
console.log(addBorder(picture));
// Expected output:
// ["*****", "*abc*", "*ded*", "*****"]