Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 755 Bytes

is-n-divisible-by.md

File metadata and controls

30 lines (22 loc) · 755 Bytes

Is n divisible by (...)? 7 Kyu

LINK TO THE KATA - FUNDAMENTALS

Description

Create a function that checks if the first argument n is divisible by all other arguments (return true if no other arguments)

Example:

(6,1,3)--> true because 6 is divisible by 1 and 3
(12,2)--> true because 12 is divisible by 2
(100,5,4,10,25,20)--> true
(12,7)--> false because 12 is not divisible by 7

Solution

const isDivisible = (number, ...otherNumbers) => {
  if (otherNumbers.length === 0) return true

  return otherNumbers.every(currentNumber => number % currentNumber === 0)
}