How to use 'javascript program to print prime numbers' in JavaScript

Every line of 'javascript program to print prime numbers' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
1function PrimeChecker (num) {
2 function permute (num) {
3 num = num.toString().split('');
4 var answerArr = [];
5 var outerLength = num.length;
6 var innerLength = 1;
7 var startItem;
8 var moveItem;
9 for (var i = 1; i < num.length; i++) {
10 innerLength *= i;
11 }
12
13 for (var j = 0; j < outerLength; j++) {
14 startItem = num[j];
15 num.splice(j, 1);
16
17 for (var k = 0; k < innerLength + 1; k++) {
18 moveItem = num.shift();
19 num.splice(k, 0, moveItem);
20 if (k < innerLength) {
21 answerArr.push(parseInt(startItem + num.join('')));
22 }
23 }
24 num.splice(j, 0, startItem);
25 }
26 return answerArr;
27 }
28
29 function isPrime (num) {
30 for (var i = 2; i < num; i++) {
31 if (num % i === 0) {
32 return false;
33 }
34 }
35 if (num === 1) {
36 return false;
37 }
38 return true;
39 }
40
41 var possibleCombos = permute(num);
42 var foundPerms = 0;
43
44 for (var k = 0; k < possibleCombos.length; k++) {
45 if (isPrime(possibleCombos[k])) {
46 foundPerms = 1;
47 }
48 }
49
50 return foundPerms;
51}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code


Related snippets