- 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

# Numbers obtained during checking divisibility by 7 using JavaScript

## Problem

We can check for a number to be divisible by 7 if it is of the form 10a + b and a - 2b is divisible by 7.

We continue to do this until a number known to be divisible by 7 is obtained; we can stop when this number has at most 2 digits because we are supposed to know if a number of at most 2 digits is divisible by 7 or not.

We are required to write a JavaScript function that takes in a number and return the number of such steps required to reduce the number to a two-digit number at most and that two digit number.

**Input**

const num = 1603;

**Output**

const output = [7, 2];

Because the steps are −

160 - 2*3 = 154 15 - 2*8 = 7

And the final value is 7

## Example

Following is the code −

const num = 1603; const findSteps = (num) => { let times = 0; let result = 0; let number = String(num); while(number.length > 2){ times++; let firstNumber = Number(number.slice(-1)) const remaining = Number(number.slice(0, number.length - 1)) result = remaining - 2 * firstNumber number = String(result) } return [result, times] } console.log(findSteps(num));

## Output

[7, 2]

- Related Articles
- Divisibility by which number is understood by checking the last two digits?
- Checking semiprime numbers - JavaScript
- Checking for vowels in array of numbers using JavaScript
- JavaScript - Checking for pandigital numbers
- Checking for Fibonacci numbers in JavaScript
- Checking for coprime numbers in JavaScript
- Checking for co-prime numbers - JavaScript
- Checking Oddish and Evenish numbers - JavaScript
- Checking for special numbers in JavaScript
- Checking for the Gapful numbers in JavaScript
- Explain the divisibility rule of 7.
- Using divisibility tests, determine which of the following numbers are divisible by 4 and by 8.(a) 572 (b) 726352
- Maximize profit when divisibility by two numbers have associated profits in C++
- Test the divisibility of the following numbers by 6 a) 5634 b) 65990
- Explain the divisibility rules of 7 and 9.

Advertisements