
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
Finding Pandigital Numbers Using JavaScript
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.
A pandigital number is a number that contains all digits (0-9) at least once.
Therefore, let’s write the code for this function −
Example
The code for this will be −
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
The output in the console will be −
false true
Advertisements