Menu

📰
0

Reddit - Please wait for verification

Learn Javascript·/u/NutelaTheNormand·3 days ago
#Gpr5hrMu
Reading 0:00
15s threshold

Tried implementing vectors from scratch, but for some reason, in the function normalize(), I get different results if i make the normalising operation using the function getMag()by itself, and with the function put into a variable. normalize(){ var len = this.getMag(); // ”Raw” method //this.x = this.x / this.getMag(); //this.y = this.y / this.getMag(); // “Processed” method //this.x = this.x / len; //this.y = this.y / len; return this; } Here’s the getMag function: getMag(){ return Math.sqrt((this.x * this.x)+( this.y * this.y)); } I’ve run multiple tests like: Printing out both methods entire process Making a simple sum operation with the same logic (first add 2 numbers that are put into variables, and the make one of the numbers be a return value of a function) And both come to the same conclusion: There should be no difference from a return value of a function by itself, and from a return value put into a variable. HELP PLS.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More