Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb214707

Browse files
Update 8-stringToInteger.js
1 parent7e5c407 commitb214707

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎Easy/8-stringToInteger.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,30 @@ var myAtoi = function(str) {
3434

3535
returnnum*sign;
3636
};
37+
38+
/**
39+
* Alternate Solution - 2020
40+
*@param {string} str
41+
*@return {number}
42+
*/
43+
/*
44+
var myAtoi = function(str) {
45+
const INT_MIN = Math.pow(-2, 31);
46+
const INT_MAX = Math.pow(2, 31) - 1;
47+
48+
const number = parseInt(str, 10);
49+
50+
if (number < INT_MIN) {
51+
return INT_MIN;
52+
}
53+
54+
if (number > INT_MAX) {
55+
return INT_MAX;
56+
}
57+
58+
if (isNaN(number)) {
59+
return 0;
60+
}
61+
62+
return number
63+
}; */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp