Skip to content

Instantly share code, notes, and snippets.

// More Efficient
function compareAll(bodies) {
// loop thru all bodies backwards : ignore first item //
for(let i = active.length - 1; i > 0; i--) {
// pull out bodyA for comparison //
const bodyA = active[i];
// loop thru all bodies backwards : start at j = i - 1 and include first item //
for(let j = i - 1; j > -1; j--) {
// pull out bodyB for comparison //
const bodyB = active[j];
// Quadratic time complexity O(N 2 ) — “Order N squared”
function compareAll(active) {
// loop thru all bodies backwards //
for(let i = active.length - 1; i > -1; i--) {
// pull out bodyA for comparison //
const bodyA = active[i];
// loop thru all bodies backwards again //
for(let j = active.length - 1; j > -1; j--) {
// pull out bodyB for comparison //
const bodyB = active[j];
@jfraboni
jfraboni / updatePosition
Created February 10, 2019 12:00
Snippet: Update a body's position and rotation
/**
* Updates the x and y properties of a body based on its
* velocityX and velocityY, and, updates the rotation of
* a body based on its rotationalVelocity.
*
* @param {Object} body: The body must be an Object
* with x, y, rotation, velocityX, velocityY, and
* rotationalVelocity properties.
*/
updatePosition(body) {
@jfraboni
jfraboni / updateVelocity
Last active February 12, 2019 01:49
Snippet: Method to update the diagonal velocity of a body
/**
* Updates the diagonal velocity properties of a body,
* taking into account the body's current velocity
* and applying any forces acting against the body
* as acceleration on both the x and y axis.
*
* NOTE: This method DOES NOT update the position of
* the body, it only updates its velocity.
*
* @param {Object} body: The body must be an Object
@jfraboni
jfraboni / grade
Last active July 31, 2017 22:41
Grade test
{
"id": 641093,
"requirementId": "JHFvd2DnH9wTkLKXT",
"sessionId": "snXgTXcxPKdCQgTh3",
"type": "PROJECT",
"tests": 16,
"passes": 15,
"failures": 1
}
/*
* VARIABLES:
*
* 0. To hold things in memory during the life-cycle of a program, we can use variables. Variables
* are named identifiers that can point to values of a particular type, like a Number, String,
* Boolean, Array, Object or another data-type. Variables are called so because once created, we
* can CHANGE the value (and type of value) to which they point.
*
* 1. To create a variable we use the keyword, var, followed by a name (id or alias) for our
* variable.
@jfraboni
jfraboni / jsbin.nigawi.js
Last active January 12, 2017 22:09 — forked from anonymous/index.html
VariablesVariables// source https://jsbin.com/nigawi
/*
* VARIABLES:
*
* 0. To hold things in memory during the life-cycle of a program, we can use variables. Variables
* are named identifiers that can point to values of a particular type, like a Number, String,
* Boolean, Array, Object or another data-type. Variables are called so because once created, we
* can CHANGE the value (and type of value) to which they point.
*
* 1. To create a variable we use the keyword, var, followed by a name (id or alias) for our
* variable.
@jfraboni
jfraboni / jsbin.jihure.js
Last active August 26, 2016 01:45 — forked from anonymous/index.html
variablesvariables// source https://jsbin.com/jihure
/*
* VARIABLES:
*
* 0. To hold things in memory during the life-cycle of a program, we can use variables. Variables
* are named identifiers that can point to values of a particular type, like a Number, String,
* Boolean, Array, Object or another data-type. Variables are called so because once created, we
* can CHANGE the value (and type of value) to which they point.
*
* 1. To create a variable we use the keyword, var, followed by a name (id or alias) for our
* variable.
suite("strings", function(){
test("toDashCase", function(done){
expect(toDashCase('Hello World')).to.equal('hello-world');
expect(toDashCase('Should Work With Many Words')).to.equal('should-work-with-many-words');
done();
});
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
// variables