DEV Community

loading...

Discussion on: Daily Challenge #12 - Next Larger Number

Collapse
kvharish profile image
K.V.Harish

My solution in js


const nextLargerNumber = (num) => {
  const largerNumber = parseInt(`${num}`.split('').sort().reverse().join(''));
  return num == largerNumber ? -1 : largerNumber;
};