Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

leetcode reverse interger solution

var reverse = function(x) {
    
  let xStr = String(Math.abs(x)).split('').reverse().join('');
  let int = parseInt(xStr); 
  
  if(int > Math.pow(2, 31)) return 0;
  if(x < 0) return -int;
  return int;  
};
Comment

leetcode reverse interger solution

/**
 * @param {number} x
 * @return {number}
 */
var reverse = function(x) {
  const toArr = String(x).split('')
  const store = []
  
  if(toArr.length > 0) {
    toArr.forEach((val) => {
        if(val !== 0 && val !== '-') {
           store.push(val)
        }
      
       if(val === 0) {
           store.push(val)
        }
      
        if(val !== 0 && val == '-') {
           store.push('-')
        }
    })
  }

 let reverse = 0
  
 if(store.includes('-')) {
   reverse = - + store.reverse().join('').replace('-', '')
 }
  
  if(!store.includes('-')) {
   reverse = store.reverse().join('').replace('-', '')
 }
  
 return parseInt(reverse)
};
Comment

leetcode reverse interger solution

var reverse = function(x) {
    
  let str = String(Math.abs(x)).split('').reverse().join('');
  let int = parseInt(str); 
  
  if(int > Math.pow(2, 31) || int > Math.pow(2, 31) - 1) return 0;

  return x < 0 ? -int : int;  
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: dot notation vs bracket notation javascript 
Javascript :: Javascript highest to lowest 
Javascript :: how to read json in c# and insert into database 
Javascript :: Scrub punctuation character 
Javascript :: add to dictionary node js 
Javascript :: adding object into object 
Javascript :: How to set variable data in JSON body for the code that generated by Postman in c# 
Javascript :: link the filename to the visible layer 
Javascript :: javascript array get element by index 
Javascript :: javascript look array 
Javascript :: jquery select convert into input text 
Javascript :: Angular bind only when mouse moves 
Javascript :: json schema script 
Javascript :: url-regex-improvement-to-allow-localhost-url 
Javascript :: bootstrapmaterialdatepicker get selected value on changes 
Javascript :: javascript random to abs 
Javascript :: scraping from amazon using puppeteer 
Javascript :: lucastools version info getter 
Javascript :: SharePoint Rest Api in Batch using PnP JS 
Javascript :: angular schematics tree 
Javascript :: linearSearch 
Javascript :: jquery selected checkboxes pass as paramater to C# 
Javascript :: check if value in mapping is empty struct in solidity ethereum 
Javascript :: .localecompare number func 
Javascript :: how to get current row value by clicking a button 
Javascript :: Exponent Power Shorthand in javascript 
Javascript :: Tableau JS api getdata 
Javascript :: the key import is reserved 
Javascript :: where to make the hooks functions 
Javascript :: js set cursor final input 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =