- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
JavaScript - Checking for pandigital numbers
A pandigital number is a number that contains all digits (0-9) at least once. We are required to write a JavaScript function that takes in a string representing a number. The function returns true if the number is pandigital, false otherwise.
Example
Following is the code to check for pandigital numbers −
const numStr1 = '47458892414'; const numStr2 = '53657687691428890'; const isPandigital = numStr => { let legend = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; for(let i = 0; i < numStr.length; i++){ if(!legend.includes(numStr[i])){ continue; }; legend.splice(legend.indexOf(numStr[i]), 1); }; return !legend.length; }; console.log(isPandigital(numStr1)); console.log(isPandigital(numStr2));
Output
Following is the output in the console −
false true
Advertisements