Q:

Write a JavaScript program to convert a value to a safe integer

0

Write a JavaScript program to convert a value to a safe integer.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const to_Safe_Integer = num =>
 Math.round(Math.max(Math.min(num, Number.MAX_SAFE_INTEGER), Number.MIN_SAFE_INTEGER));
console.log(to_Safe_Integer('5.2'));
console.log(to_Safe_Integer('5.52'));
console.log(to_Safe_Integer(Infinity)); 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now