# LeetCode: Count Integers With Even Digit Sum Solution

Map and filter

## Approach

Populate new array with digit sum

Filter even elements

## Implementation

```.css-ds3kc{display:table-row;}.css-1t8atru{display:table-cell;opacity:0.5;padding-right:var(--chakra-space-6);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;text-align:right;}1.css-2qghsv{display:table-cell;}var countEven = function (num) {2  const digitSum = num =>3    num4      .toString()5      .split("")6      .map(Number)7      .reduce((acc, el) => acc + el, 0)8
9  const isEven = num => num % 2 === 010
11  return Array.from({ length: num }, (_, i) => i + 1)12    .map(digitSum)13    .filter(isEven).length14}```

Original problem

## Similar problems

Sum of Numbers With Units Digit K

Sum of Digits of String After Convert

Number of Ways to Buy Pens and Pencils

leetcode

math

string

array

## Next Post

LeetCode: Special Positions in a Binary Matrix

Oct 12, 2022

Count number of 1s

Search Posts