Reputation: 1776
npc_objects = {};
TURKEYLENGTH = (Math.max.apply(Math, Object.keys(npc_objects))) + 1;
console.log(TURKEYLENGTH);
Fiddle: http://jsfiddle.net/j40ucf6m/1/
As pertinent to my most recent question asked :P.. I just found out that -Infinity
is actually a numerical value. I'm trying to add another numerical value to it, but it's still returning -Infinity
. I have tried to move the +1 inside the parenthesis aswell. For example (Math.max.apply(Math, Object.keys(npc_objects))+1);
Upvotes: 2
Views: 472
Reputation: 136717
Just as a side note, and because we're speaking about javascript,
There is a value just before Infinity
.
I have no resource about it, but it seems that the largest value before Infinity
is -179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497791.99999 //+ infinity of 9
.
And you can take the same number *-1
to find the cliff before -∞
There is also a cliff before a float number becomes an int, look at the snippet.
var cliffBeforeInfinity = 179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497791.99999; //+ infinity of 9
var realInfinity= 179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497792;
var almost_zero = 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024703282292062327208828439643411068618252990130716238221279284125033775363510437593264991818081799618989828234772285886546332835517796989819938739800539093906315035659515570226392290858392449105184435931802849936536152500319370457678249219365623669863658480757001585769269903706311928279558551332927834338409351978015531246597263579574622766465272827220056374006485499977096599470454020828166226237857393450736339007967761930577506740176324673600968951340535537458516661134223766678604162159680461914467291840300530057530849048765391711386591646239524912623653881879636239373280423891018672348497668235089863388587925628302755995657524455507255189313690836254779186948667994968324049705821028513185451396213837722826145437693412532098591327667236328125001;
var zero = 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000247032822920623272088284396434110686182529901307162382212792841250337753635104375932649918180817996189898282347722858865463328355177969898199387398005390939063150356595155702263922908583924491051844359318028499365361525003193704576782492193656236698636584807570015857692699037063119282795585513329278343384093519780155312465972635795746227664652728272200563740064854999770965994704540208281662262378573934507363390079677619305775067401763246736009689513405355374585166611342237666786041621596804619144672918403005300575308490487653917113865916462395249126236538818796362393732804238910186723484976682350898633885879256283027559956575244555072551893136908362547791869486679949683240497058210285131854513962138377228261454376934125320985913276672363281245;
var p = document.querySelector('p');
p.innerHTML+='cliff Before Infinity : '+cliffBeforeInfinity;
p.innerHTML+='<br>';
p.innerHTML+='Infinity : '+ realInfinity;
p.innerHTML+='<br>';
p.innerHTML+='cliff before -Infinity : '+cliffBeforeInfinity*-1;
p.innerHTML+='<br>';
p.innerHTML+='-Infinity : '+realInfinity*-1;
p.innerHTML+='<br>';
p.innerHTML+='almost zero : '+almost_zero;
p.innerHTML+='<br>';
p.innerHTML+='zero : '+ zero;
<p></p>
Upvotes: 2
Reputation: 128791
Unless you add Infinity
to -Infinity
you will always get the answer -Infinity
(adding Infinity
to it will give you NaN
). If we were to know what -Infinity + 1
is equal to, we'd then know what -Infinity
is equal to (as a number), and this would make it a finite number and not an infinite number.
Upvotes: 6