Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions javascript/2520-count-the-digits-that-divide-a-number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @param {number} num
* @return {number}
*/
var countDigits = function (num) {
let count = 0; // initialize count to zero
let arr = num.toString().split(''); // make array arr from num using toSting() and split()

for (let i = 0; i < arr.length; i++) { // loop through the every element of array
if (num % arr[i] == 0) { // if num is divisable by current element of array arr then increment count
count++;
}
}
return count; // return count
};