const repeat = (str:string, times:number):string =>{
  let result = str;

  for (let i = 0; i < times; i++) {
    result += str;
  }

  return result;
};

const longestStr = (list:string[]):string =>{
  let longest = list[0];
  list.forEach((word:string) => {
    if (word.length > longest.length)
      longest = word;
  })
  return longest;
};

const printInFrame = (list:string):void => {
  const words:string[] = list.split(' ');
  const longest:number = longestStr(words).length;
  const border:string = repeat('*', longest + 4);

  console.log(border);
  for (const word of words) {
    console.log(`* ${word}${repeat(' ', longest - word.length + 1)}*`);
  }
  console.log(border);
};

export default printInFrame;