repl.it
@bbenefield89/

TS: Round Nearest Whole N

TypeScript

No description

fork
loading
Files
  • index.ts
  • index.test.ts
  • tsconfig.json
  • Packager files
  • package.json
index.ts
1
2
3
4
5
function roundToNearestWholeNumber(x: number, y: number): number {
  return Math.round(x / y) * y === 0 ? y : Math.round( x / y )*y
}

console.log(roundToNearestWholeNumber(1,5))
?