nunof07/phaser-breakout

View on GitHub
src/systems/bricks/lowestY.ts

Summary

Maintainability
B
4 hrs
Test Coverage
import { Brick } from '@systems/bricks/Brick';
 
/**
* Determine Y coordinate for brick in lowest position (most at the bottom). This will actually be the maximum Y of all bricks.
* @param bricks Bricks.
* @param defaultValue Default value if no bricks.
*/
Similar blocks of code found in 2 locations. Consider refactoring.
export function lowestY(bricks: ReadonlyArray<Brick>, defaultValue: number): number {
return bricks.length === 0
? defaultValue
: bricks.reduce((prev: Brick, curr: Brick) => prev.sprite().y > curr.sprite().y ? prev : curr)
.sprite().y;
}