repl.it
@bbenefield89/

GIS, Inc

Nodejs

No description

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function roundToNearestWholeNumber(x, y) {
  if (x.constructor.name === 'Number' && y.constructor.name === 'Number') {
    const rounded = Math.round(x / y) * y
    return rounded || y
  }
  else {
    return 'X and Y must be an Integer'
  }
}

console.log(roundToNearestWholeNumber(54, 50))
console.log(roundToNearestWholeNumber(75, 100))
console.log(roundToNearestWholeNumber(98, 100))
console.log(roundToNearestWholeNumber(119, 100))

console.log(roundToNearestWholeNumber(22, 22))
console.log(roundToNearestWholeNumber(29, 22))
console.log(roundToNearestWholeNumber(33, 44))
console.log(roundToNearestWholeNumber(47, 44))

console.log(roundToNearestWholeNumber('47', 44))
console.log(roundToNearestWholeNumber({ x: 47 }, 44))
console.log(roundToNearestWholeNumber([47], 44))
console.log(roundToNearestWholeNumber(true, 44))

console.log(roundToNearestWholeNumber(47, '44'))
console.log(roundToNearestWholeNumber(47, { y: 44 }))
console.log(roundToNearestWholeNumber(47, [44]))
console.log(roundToNearestWholeNumber(47, false))
?