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

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:47:16+05:30 · Edit