You are given an array of non-negative integers numbers. You are allowed to choose any number from this array and swap any two digits in it. If after the swap operation the number contains leading zeros, they can be omitted and not considered (eg: 010 will be considered just 10). Your task is to check whether it is possible to apply the swap operation at most once, so that the elements of the resulting array are strictly increasing.
function isPossible(numbers) { const indexOfZero = numbers.indexOf(0); if (indexOfZero === -1) { return false; } if (indexOfZero === 0) { numbers = numbers.slice(1); } const number = parseInt(numbers.join('')); return ( number + 1 === parseInt((indexOfZero + numbers.slice(1).join(''))) || number - 1 === parseInt(numbers.slice(0, -1).join('')) ); }