- 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
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
- Related Articles
- JavaScript - Checking for pandigital numbers
- What are pandigital numbers. Approach to find the pandigital Numbers using C++
- Finding tidy numbers - JavaScript
- Finding perfect numbers in JavaScript
- Finding sum of remaining numbers to reach target average using JavaScript
- Finding lunar sum of Numbers - JavaScript
- Finding special type of numbers - JavaScript
- Finding two golden numbers in JavaScript
- Finding two numbers given their sum and Highest Common Factor using JavaScript
- Finding three desired consecutive numbers in JavaScript
- Finding the count of total upside down numbers in a range using JavaScript
- Finding Lucky Numbers in a Matrix in JavaScript
- Finding the nth digit of natural numbers JavaScript
- Finding the count of numbers divisible by a number within a range using JavaScript
- Finding desired numbers in a sorted array in JavaScript

Advertisements