Assuming we only accept one character for the middle and the surrounding.
"use strict"/**
* Surround a character with some more character N times
*
* @param {string} middleCharacter The character to insert in the middle of the string
* @param {string} surroundingCharacters The character that will surround the middle one
* @param {number} repeatCount The number of times the surrounding character will be repeated
* @throws {Error} If the argument count is not three
* @throws {TypeError} If the first argument is not a string
* @throws {TypeError} If the second argument is not a string
* @throws {TypeError} If the third argument is not a number
* @throws {TypeError} If the first argument has a length different than one
* @throws {TypeError} If the second argument has a length different than one
* @throws {TypeError} If the third argument is lower than one
* @return {string} The middle character with its surrounding characters
*/functionmiddleMe(middleCharacter:string,surroundingCharacters:string,repeatCount:number):string{if(arguments.length!==3){thrownewError("Three arguments expected")}if(typeofmiddleCharacter!=="string"){thrownewTypeError("First argument expected to be a string")}if(typeofsurroundingCharacters!=="string"){thrownewTypeError("Second argument expected to be a string")}if(typeofrepeatCount!=="number"){thrownewTypeError("Third argument expected to be a string")}if(middleCharacter.length!==1){thrownewError("First argument must have a length of one")}if(surroundingCharacters.length!==1){thrownewError("Second argument must have a length of one")}if(repeatCount<1){thrownewError("Third argument must be greater or equal to one")}if(repeatCount%2!==0){returnmiddleCharacter}constcomputedSurroundingCharacters:string=surroundingCharacters.repeat(repeatCount/2)return`${computedSurroundingCharacters}${middleCharacter}${computedSurroundingCharacters}`}
TypeScript
Assuming we only accept one character for the middle and the surrounding.
Playground
Repl.it.