code.ashish.me

Atom feed

Recently added: 128 Longest Consecutive Sequence, 347 Top K Frequent Elements, 045 Jump Game 2, 228 Summary Ranges, 219 Contains Duplicate 2

045 Enclose In Brackets

/**
 * 
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

/* 
Given a string, enclose it in round brackets.

Example

For inputString = "abacaba", the output should be encloseInBrackets(inputString) = "(abacaba)".
*/

function encloseInBrackets(value) {
  value = value.split('')
  value.push(')')
  value.unshift('(')
  return value.join('')
}

test('enclose In Brackets', () => {
  expect(encloseInBrackets('abacaba')).toEqual('(abacaba)')
});

Created 2019-12-14T23:23:16+05:30 · Edit