LeetCode: Number of Common Factors Solution

Iterate

Approach

Iterate from 1 to max of a and b and count the number of divisible

Implementation

1var commonFactors = function (a, b) {
2 return Array.from(
3 { length: Math.max(a, b) + 1 },
4 (_, i) => a % i === 0 && b % i === 0
5 ).filter(Boolean).length
6}

References

Original problem

Similar problems

Count Primes

Comments

Loading comments...

Tags

leetcode

math

array

Next Post

LeetCode: Count Integers With Even Digit Sum

Map and filter

Previous Post

HoningJS

Search Posts