onlycode.org

javascript
jquery
html
angularjs
css
node.js
ajax
html5
php
json
arrays
google-chrome
dom
regex
reactjs
ecmascript-6
javascript-events

your's history:
why is lt slower than lt...

Why is <= slower than < in V8, just only code?

v8 | javascript

edit
let array = [];
a[0] = 10;
a[2] = 20;

28
Michael Geary, 06.12.2018 05:34




edit
var iterations = 25000;

function Primes() {
  this.prime_count = 0;
  this.primes = new Array(iterations);
  this.getPrimeCount = function() { return this.prime_count; }
  this.getPrime = function(i) { return this.primes[i]; }
  this.addPrime = function(i) {
    this.primes[this.prime_count++] = i;
  }
  this.isPrimeDivisible = function(candidate) {
    for (var i = 1; i <= this.prime_count; ++i) {
      if ((candidate % this.primes[i]) == 0) return true;
    }
    return false;
  }
};

function main() {
  var p = new Primes();
  var c = 1;
  while (p.getPrimeCount() < iterations) {
    if (!p.isPrimeDivisible(c)) {
      p.addPrime(c);
    }
    c++;
  }
  console.log(p.getPrime(p.getPrimeCount() - 1));
}

main();
this.primes = new Array(iterations);
if ((candidate % this.primes[i]) == 0) return true;
for (var i = 1; i <= this.prime_count; ++i) {

27
Mathias Bynens, 07.12.2018 14:31




edit
var arr_five_char=['a', 'b', 'c', 'd', 'e']; // arr_five_char.length === 5
//  indexes are:    0 ,  1 ,  2 ,  3 ,  4    // there is NO index number 5
function sum(arr){
  var r=0, i=0;
  for(;i<arr.length;) r+=arr[i++];
  return r;
}
sum('abcde');   // String('0abcde')
sum([1,2,3]);   // Number(6)
sum([1,,3]);    // Number(NaN)
sum(['1',,3]);  // String('01undefined3')
sum([1,,'3']);  // String('NaN3')
sum([1,2,{valueOf:function(){return this.val}, val:6}]);  // Number(9)
var val=5; sum([1,2,{valueOf:function(){return val}}]);   // Number(8)

26
GitaarLAB, 07.12.2018 03:28

Add your just only code

your name:    



If you need full text click here

Some similar links Why is <= slower than < in V8? ↓:
Why is bind slower than a closure?

Why is accessing a variable using window.variable slower?

In javascript, is accessing 'window.Math' slower or faster than accessing the 'Math' object without the 'window.'?



This project is created for those who just need only code, wihout maaaaaaaaaaany words.