Resolved => Problème JS | Sololearn: Learn to code for FREE!

+14

Resolved => Problème JS

Hello, I have a problem in js with a large number return. See code Than you ! https://code.sololearn.com/WQ79Q0e3N18g/?ref=app

4/19/2019 7:03:56 PM

lolo

30 Answers

New Answer

+9

lololearn you could just convert number to BigInt(number) then your function would process large number without issue. https://code.sololearn.com/W0mGYboi2Ci0/?ref=app

+10

What exactly you need, the red numbers to be the same result as the green numbers?

+10

Yes, putting the number inside quotes as bobbie say https://code.sololearn.com/WMWO0Nzqx3ul/?ref=app

+9

Use built in method, BigInt for unsafe number calculation https://code.sololearn.com/W3eNWFfXF1Zu/?ref=app

+9

lololearn This worked (inside the for loop) replace result*=i with: result=BigInt(result)*BigInt(i); most likely conversion issue only reason that the variable "i" also needs casting to BigInt is that you cannot mix BigInt with a primitive integer (try it and see the error that is thrown)

+8

Burey you are an undisputed GENIUS! I researched that few thought it's even possible!

+8

lololearn I would love to see HTML6 include a way to embed Python into web codes it's such a great language. But im also starting to believe Burey can do anything with Javascript why bother lol.

+8

Use Number.isSafeInteger method to check for integer is safe or unsafe. https://code.sololearn.com/W6SVyP904LOB/?ref=app

+8

Thanks Calviղ! I love learning new things from you! PS why is my php not working in my web code?

+7

lololearn you can convert it back and forth from string as needed. Please give us an example of how you intend to use it if you need more help.

+6

Have you tried putting quotes " " around it?

+6

Perhaps this will help? https://medium.com/@nitinpatel_20236/javascript-adding-extremely-large-numbers-and-extra-long-factorials-229b6055cb1a http://2ality.com/2012/07/large-integers.html

+6

lololearn Also take a look into this library: https://github.com/rauschma/strint it was mentioned in the second article and was not so easy to find 😅 Take into account it does not seem to work in SL playground edit: another option is to try using a library such as https://mathjs.org for the operations

+6

Burey great to see you here! I found a PHP and a Ruby solution I thought we could just plug one of those in the HTML for our extended brain but I keep messing it up? https://code.sololearn.com/Wa6L1S2XGGbO/?ref=app https://code.sololearn.com/w766RX55RQ6L/?ref=app https://code.sololearn.com/cXd0I7p4Me1E/?ref=app

+6

lololearn Seems the "add" function given in the first article made it work article: https://medium.com/@nitinpatel_20236/javascript-adding-extremely-large-numbers-and-extra-long-factorials-229b6055cb1a https://code.sololearn.com/WoGrVpsgUAdB/?ref=app

+6

😱 than you It s working !

+6

The article explains it very well :)

+6

Thank you all ! Burey you are a genius, Calviղ is perfect! I met this problem several times and each time I was stuck on the exercise. Sololearn has the best community, it's incredible sharing between members 👍 👏👏👏 🥇🏆

+6

Calviղ An idea why this code with BigInt does not give the right result. Thx https://code.sololearn.com/W21sTojWav3F/?ref=app

+6

Burey Yes it makes sense! I am a beginner in JS but I found a master 👏👏👏 Thank you so much