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

004 Add Two Digits

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

// You are given a two-digit integer n. Return the sum of its digits.

// Example

// For n = 29, the output should be addTwoDigits(n) = 11.

function addTwoDigits(values) {
  const nums = values.toString().split('')
  return nums.reduce((i, sum) => Number(i) + Number(sum))
}

test('add Two Digits', () => {
  expect(addTwoDigits(29)).toEqual(11)
})

Created 2019-12-05T02:35:16+05:18 · Edit