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

046 Even Digits Only

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

/* 
Check if all digits of the given integer are even.

Example

For n = 248622, the output should be evenDigitsOnly(n) = true;
For n = 642386, the output should be evenDigitsOnly(n) = false.
*/

function evenDigitsOnly(value) {
  return value.toString().split('').every(value => parseInt(value) % 2 === 0)
}

test('even Digits Only', () => {
  expect(evenDigitsOnly(248622)).toEqual(true)
  expect(evenDigitsOnly(642386)).toEqual(false)
});

Created 2019-12-14T23:11:16+05:18 · Edit