diff --git a/javascript/2520-count-the-digits-that-divide-a-number.js b/javascript/2520-count-the-digits-that-divide-a-number.js new file mode 100644 index 000000000..a44046084 --- /dev/null +++ b/javascript/2520-count-the-digits-that-divide-a-number.js @@ -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 +}; \ No newline at end of file