4 ms·
What language is this? I was surprised to see that averagePosition /= count; apparently means averagePosition.x /= count; averagePosition.y /= count; I thin
by default-kramer 8y ago
What language is this? I was surprised to see that
averagePosition /= count;
apparently means
averagePosition.x /= count;
averagePosition.y /= count;
I think?
- Retr0spectrum 8y agoThis language feature (at a fundamental level) is called "operator overloading", which is present in a lot of languages (more often in OO languages). https://en.wikipedia.org/wiki/Operator_overloading https://en.wikipedia.org/wiki/Operator_overloading
- fenwick67 8y agoJavascript doesn't support operator overloading, I think the code in the examples is just pseudocode.
- SloopJon 8y agoThis looks like buggy JavaScript. The cohesion() function in the script element at the end of the post is a little different than the calculateCohesion() function described in the post: var averagePosition; if (count > 0) { averagePosition = { x: positionSum.x / count, y: positionSum.y / count }; } else { return {x: 0, y:0}; }
- oblib 8y agoThe author, Drew Cutchins, says "If you inspect the source code of the page you can see the code I used to implement the simulations."