- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is the digit divisible by the previous digit of the number in JavaScript
Problem
We are required to write a JavaScript function that takes in a number and checks each digit if it is divisible by the digit on its left and returns an array of booleans.
The booleans should always start with false because there is no digit before the first one.
Example
Following is the code −
const num = 73312; const divisibleByPrevious = (n = 1) => { const str = n.toString(); const arr = [false]; for(let i = 1; i < str.length; ++i){ if(str[i] % str[i-1] === 0){ arr.push(true); }else{ arr.push(false); }; }; return arr; }; console.log(divisibleByPrevious(num));
Output
[ false, false, true, false, true ]
- Related Articles
- Find the largest 4 digit number divisible by 16.
- Determine the greatest four-digit number which is exactly divisible by 10,12,16.?
- Sum of a two-digit number and the number obtained by reversing the digits is always divisible by?
- C++ Program for the Largest K digit number divisible by X?
- Find the smallest 5-digit number which is divisible by 12, 18, 30.
- Which is the smallest 4-digit number divisible by 8, 10 and 12?
- Find the smallest 4-digit number which is divisible by 18,24 and 32 .
- Find the greatest 3 digit number which is divisible by the number 4 ,5 and 6.
- Largest K digit number divisible by X in C++
- Find the least number of 5 digit that is exactly divisible by 16,18,24 and 30
- Determine the smallest 3-digit number which is exactly divisible by 6,8 and 12.
- Find the smallest 5 digit number which is exactly divisible by 20,25 and 30.
- Find the smallest 4 digit number which is exactly divisible by 18, 24, 36.
- Find the greatest 5 digit number that is exactly divisible by 22,25 and 30
- Find the number of all three digit natural numbers which are divisible by 9.

Advertisements