function encloseInBrackets = str => `(${str})`
// METHOD TWO // Statically add brackets
function encloseInBrackets = str => {
str = str.split(''), str.splice(0,0,'(') && str.splice(str.length,0,')')
return str.join('').toString()
}
// METHOD THREE // Dynamically add the brackets
function encloseInBrackets = str => {
str = str.split('')
if(str[0] === '(') str[0]
else str.splice(0,0,'(')
if(str[str.length - 1] === ')') str[str.length - 1]
else str.splice(str.length,0,')')
return str.join('').toString()
}
// METHOD FOUR // Dynamically add the brackets
function encloseInBrackets = str => {
str = str.split('')
if(str[0] === '(') str[0]
else str.unshift('(')
if(str[str.length - 1] === ')') str[str.length - 1]
else str.push(')')
return str.join('').toString()
}
console.log(encloseInBrackets('brackets)'))