Toggle navigation
Golibrary Code Playground - Everyone for education
Run
(current)
Fork
Settings
Share
0
379
Anonymous
HTML/CSS/Javascript
Python
Ruby
Clojure
PHP
Javascript (NodeJS)
Scala
Go
C/C++
Java
VB.Net
C#
Bash
Objective C
MySQL
Perl
Rust
HTML/CSS/Javascript
Search
Login
Login
Reset Password ?!
Login
Register
×
RESET PASSWORD
@
×
Allowed Extensions
Only this extensions are allowed: jpg,png,gif,jpeg
×
Error Message
×
Share this code
Url of this code
Send SMS with url of this code
Save As Github Gist
×
Github Gist
×
SETTINGS
HTML
CSS
Javascript
Title
Description
Meta Tags
Add meta tag example
Known ressources
--
Foundation
Bootstrap
CSS Preprocessor
CSS
LESS
SCSS
External CSS
Add another ressource
Known ressources
--
JQuery UI
Modernizr
Tree.js
JQuery
External JS
Add another ressource
CSS
→
/* CSS */ background: #f9f9f9; height: 100%;
Full Screen
Javascript
→
var map = {}; init(); function init() { var n = 1.9195796e+20, output = []; findPrimeFactors(n, output); document.write('Prime factors of '+n+' are: '+output); } // checks if the given number is prime function isPrime(number, getIndex = false) { for (var t = 2; t <= Math.round(Math.sqrt(number)); t++) { if (number % t === 0) { if (getIndex) return t; return false; } } return true; } // find prime factors of given number. Returns an array of prime factors of number function findPrimeFactors(num, factors = []) { if (isPrime(num)) { if (typeof map[num] === 'undefined') { factors.push(num); map[num] = num; } return factors; } // check if number if even if (num % 2 === 0) { // check if number is even and push even factor in output array if (typeof map[2] === 'undefined') { map[2] = 2; factors.push(2); } findPrimeFactors(parseInt(num / 2), factors); // recursive call. Continue until all prime factors are found } else { // check if number is odd or prime and push prime/odd factor in output array var j = isPrime(num, true); if ( j >= 2) { if (typeof map[j] === 'undefined') { map[j] = j; factors.push(j); } } findPrimeFactors(parseInt(num/j), factors); // recursive call. Continue until all prime factors are found } }
HTML
→
<!-- HTML --> <b>Start new code !</b>