
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Largest 5-Digit Number in Input Using JavaScript
Problem
We are required to write a JavaScript function that takes in a string number of at least five digits. Our function should return the greatest sequence of five consecutive digits found within the number given.
Example
Following is the code −
const num = '123546544'; const findGreatestFiveDigit = (num = '') => { const str = num.toString(); const arr = []; for(let i = 0; i < str.length; i++){ arr.push(str.slice(i, i + 5)); }; return Math.max(...arr); }; console.log(findGreatestFiveDigit(num));
Output
54654
Advertisements