Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Reverse Integer in JavaScript

/**
 * @param {number} x
 * @return {number}
 */
var reverse = function(x) {
    x = x + '';

    let reversedStr = x.split('').reverse().join('');
    
    if(reversedStr.includes('-')) {
        reversedStr = reversedStr.split('-')[0]
        reversedStr = '-'+reversedStr
    }
    if(2147483647 < reversedStr || -2147483648 > reversedStr) {
        return 0
    }
    return reversedStr
    
};
Source by exploretech.dev #
 
PREVIOUS NEXT
Tagged: #Reverse #Integer #JavaScript
ADD COMMENT
Topic
Name
6+1 =