
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Count number of factors of a number - JavaScript
We are required to write a JavaScript function that takes in a number and returns the count of numbers that exactly divides the input number.
For example −
If the number is 12, then its factors are −
1, 2, 3, 4, 6, 12
Therefore, the output should be 6.
Example
Following is the code −
const num = 12; const countFactors = num => { let count = 0; let flag = 2; while(flag <= num / 2){ if(num % flag++ !== 0){ continue; }; count++; }; return count + 2; }; console.log(countFactors(num)); console.log(countFactors(2)); console.log(countFactors(454)); console.log(countFactors(99));
Output
Following is the output in the console −
6 2 4 6
- Related Articles
- Find all prime factors of a number - JavaScript
- Decimal count of a Number in JavaScript
- Count number of pairs (A
- How to count digits of given number? JavaScript
- Product of factors of number in C++
- C++ Program to Display Factors of a Number
- Prime factors of a big number in C++
- Java Program to Display Factors of a Number
- Golang Program to Display Factors of a Number
- Haskell Program to Display Factors of a Number
- JavaScript Get English count number
- Find sum of even factors of a number using C++.
- Find sum of odd factors of a number using C++.
- How to count the number of elements in an array below/above a given number (JavaScript)
- C++ code to count number of weight splits of a number n

Advertisements