-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move distanceXY and factorial to dot/js/util/, phetsims/models-of-the…
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2025, University of Colorado Boulder | ||
|
||
/** | ||
* Returns the distance between 2 points, given by (x,y) coordinates. | ||
* | ||
* @author Chris Malley ([email protected]) | ||
*/ | ||
export default function distanceXY( x1: number, y1: number, x2: number, y2: number ): number { | ||
const dx = x1 - x2; | ||
const dy = y1 - y2; | ||
return Math.sqrt( dx * dx + dy * dy ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2025, University of Colorado Boulder | ||
|
||
/** | ||
* Computes the factorial of a non-negative integer n without using recursion. | ||
* n! = 1 * 2 * ... * ( n - 1 ) * n | ||
* | ||
* @author Chris Malley ([email protected]) | ||
*/ | ||
export default function factorial( n: number ): number { | ||
assert && assert( Number.isInteger( n ) && n >= 0, `n must be a non-negative integer: ${n}` ); | ||
let f = 1; | ||
for ( let i = 2; i <= n; i++ ) { | ||
f *= i; | ||
} | ||
return f; | ||
} |