Enclose in Brackets
// METHOD ONE // Statically add brackets
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)'))
Also in JavaScript:
- node.js
- hello world in jsp
- vs code terminal json object not showing something shows [object]
- how to get values from select multiple in js
- operator to return specific data of a mongodb query
- javascript get index of object with value in array
- js add event listener
- what is ... in javascript
- javascript array remove element
- animation library react
- difference between e.preventdefault and e.stoppropagation and return false
- aktuelle session id auslesen jsf
- Prevent Double Submit with JavaScript
- jquery multiple selectors
- how get parent element javascript
- transformorigin gsap
- javascript genreate number id
- change checkbox jquery alert
- how to add multiple comment in react
- implicit return arrow function
- use javascript library in react
- javascript fisher yates shuffle mdn
- getpermutation js recursion
- linkedin api nodejs tutorial