Skip to content

Commit 515969b

Browse files
authored
Merge pull request vJechsmayr#147 from LorTrindade/feature/myatoifunction
create function to convert string to integer
2 parents 6280294 + 03a2087 commit 515969b

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var myAtoi = function (str) {
2+
var INT_MAX = Math.pow(2, 31) - 1;
3+
var INT_MIN = Math.pow(-2, 31);
4+
5+
if (isNaN(parseInt(str))) {
6+
return 0;
7+
} else if (parseInt(str) >= INT_MAX) {
8+
return INT_MAX;
9+
} else if (parseInt(str) <= INT_MIN) {
10+
return INT_MIN;
11+
} else {
12+
return parseInt(str);
13+
}
14+
15+
};

0 commit comments

Comments
 (0)