整数反转
作者:互联网
实现:
var reverse = function(x) { let borderValue = Math.pow(2, 31); let reverseStr = x.toString().split('').reverse().join(''); let value; if (x < 0) { // 为负数 value = Number('-' + reverseStr.slice(0, -1)); return value > -borderValue ? value : 0; } else { value = Number(reverseStr); return value < borderValue -1 ? value : 0; } };
标签:reverse,反转,Number,value,let,整数,reverseStr,borderValue 来源: https://www.cnblogs.com/Tiboo/p/12018493.html