code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

709 To Lower Case

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

/* 
 * Implement function ToLowerCase() that has a string parameter str,
 * and returns the same string in lowercase.
 * 
 * Example 1:
 * Input: "Hello"
 * Output: "hello" 
 */

function toLowerCase(value) {
  let result = []
  for (let index = 0; index < value.length; index++) {
    if(value.charCodeAt(index) >= 65 && value.charCodeAt(index) < 90){
      result.push(String.fromCharCode(value.charCodeAt(index) + 32))
    } else {
      result.push(value[index])
    }    
  }
  return result.join('')
}

test('to Lower Case', () => {
  expect(toLowerCase('Ashish')).toEqual('ashish')
});

Created 2020-04-20T21:12:22+00:00 · Edit