My Solution to Javascript


  • 0
    P
    var isNumber = function(str) {
        if(["string", "number"].indexOf(typeof str) === -1){
            return false;
        }
        
        if(typeof str === "string"){
            str = str.replace(/^\s+|\s+$/g, "");
            if(str === ''){
                return false;
            }
        }
        
        return !isNaN(Number(str));
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.