Skip to content

Instantly share code, notes, and snippets.

@ChickenFur
Created November 24, 2019 20:27
Show Gist options
  • Save ChickenFur/47b579b2735c3db8d3155e663901be16 to your computer and use it in GitHub Desktop.
Save ChickenFur/47b579b2735c3db8d3155e663901be16 to your computer and use it in GitHub Desktop.
submission 7
var numberOutofBounds = (numbers: Array<string>) => {
if (numbers.length > 10) {
return true;
}
if (numbers.length <= 9) {
return false;
}
//
//2, 147, 483, 648;
const bounds = {
0: 2,
1: 1,
2: 4,
3: 7,
4: 4,
5: 8,
6: 3,
7: 6,
8: 5,
9: 0
};
for (var i = 0; i < numbers.length; i++) {
if (numbers[i] > bounds[i]) {
return true;
}
if (numbers[i] < bounds[i]) {
return false;
}
}
return false;
};
var reverse = function(x: number) {
console.log("number is", x);
var numArray = `${x}`.split("");
var negative = false;
if (numArray[0] === "-") {
negative = true;
numArray = numArray.slice(1);
}
var reversedArray = numArray.reverse();
if (numberOutofBounds(reversedArray)) {
return 0;
}
if (negative) {
return -Number(reversedArray.join(""));
}
return Number(reversedArray.join(""));
};
console.log(reverse(1563847412));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment