Nodejs Number Prime Number Check primeFactorization()

Here you can find the source of primeFactorization()

Method Source Code

Number.prototype.primeFactorization = function () {

    var ans = [];
    var primes = [];
    var temp = this;
    for (let i = 2; i <= temp / 2; i++) {
        if (i.divisors().length == 2) {
            primes.push(i);//from  www  .  j ava 2s .  co m
        }
    }

    for (let i = 0; i < primes.length; i++) {
        while (temp.isDevisor(primes[i])) {
            ans.push(primes[i]);
            temp = temp / primes[i];
        }
    }

    return ans;
}

Related

  1. isPrime()
    Number.prototype.isPrime = function () {
      var i = 2;
      while (i<=this - 1) {
        if (this % i ==0) {
          return false;
          break;
        i++;
      if (i == this) {
        return true;
    };
    
  2. primeFactorization()
    Number.prototype.primeFactorization = function(){
         var ans = [];
        var primes = [];
        var temp = this;
        for(let i=2; i<=this/2; i++){
            if(i.divisors().length==2){
                primes.push(i)
        for(let i = 0; i<primes.length;i++){
            while(temp.isDivisor(primes[i])){
                ans.push(primes[i]);
                temp = temp/primes[i];
        return ans;
    
  3. primeFactorization()
    Number.prototype.primeFactorization = function() {
      var ans = [];
      var primes = [];
      var temp = this;
      for (let i = 0; i <= temp/2; i++) {
        if (i.allDivisors().length == 2) {
          primes.push(i)
      for (let i = 0; i < primes.length; i++) {
        while (temp.isDivisor(primes[i])) {
          ans.push(primes[i]);
          temp = temp / primes[i];
      console.log(ans);
    
  4. primeFactorization()
    Number.prototype.primeFactorization = function(){
      var ans = [];
      var temp = this;
      var primes = [];
      for(let i = 2;i<=this/2;i++){
        if(i.divisors().length == 2){
          primes.push(i);
          if(temp==1){
            break;
    ...
    
  5. primeFactorization()
    Number.prototype.primeFactorization = function () {
        var ans = [];
        var primes = [];
        var temp = this;
        for (let i = 2; i <= temp / 2; i++) {
            if (i.divisors().length == 2) {
                primes.push(i);
        for (let i = 0; i < primes.length; i++) {
            while (i.isDivisor(temp)) {
                ans.push(primes[i]);
                temp = temp / primes[i];
        return ans;
    
  6. primeFactorization()
    Number.prototype.primeFactorization = function (){
        console.log("prime aangekomen");
        var ans = [];
        var primes = [];
        var temp = this;
        for(let i = 2; i<temp/2; i++){
            if(i.divisors().length == 2){
                primes.push(i);
        for (let i =0; i<primes.length; i++){
                while(temp.isDivisor(primes[i])){
                    ans.push(primes[i]);
                    temp = temp/primes[i];
        return ans;
    };
    
  7. primeFactorization()
    Number.prototype.primeFactorization = function () {
        "use strict";
        var ans = [];
        var primes = [];
        var temp = this;
        for (let i = 2; i <= this / 2; i += 1) {
            if (i.divisors().length == 2) {
                primes.push(i);
        for (let i = 0; i < primes.length; i += 1) {
            while (temp.isDivisor(primes[i])) {
                ans.push(primes[i]);
                temp = temp / primes[i];
        return ans;
    };
    
  8. primeFactors()
    "use strict";
    Number.prototype.primeFactors = function() {
      var v, i;
      v = null;
      for (i = 2; i < this - 1; i += 1) {
        if (this % i === 0) {
          v = i;
          break;
      if (v) {
        return [v].concat(Math.floor(this / v).primeFactors());
      } else {
        return [this];
    };
    console.log(Math.max.apply(null, (600851475143).primeFactors()));
    
  9. primeFactors()
    "use strict";
    var i, j, triangleNumber;
    Number.prototype.primeFactors = function() {
      var v, i;
      v = null;
      for (i = 2; i < this - 1; i += 1) {
        if (this % i === 0) {
          v = i;
          break;
    ...