diff --git a/520.detect-capital.js b/520.detect-capital.js new file mode 100644 index 0000000..923cd2a --- /dev/null +++ b/520.detect-capital.js @@ -0,0 +1,18 @@ +/** + * URL of this problem + * https://leetcode.com/problems/detect-capital/ + */ + +/** + * @param {string} word + * @return {boolean} + */ +var detectCapitalUse = function (word) { + const AllCapitalLetter = word.toUpperCase(); + const AllLowerCaseLetter = word.toLowerCase(); + const FirstCapitalLetter = word.charAt(0).toUpperCase() + AllLowerCaseLetter.slice(1); + + if (AllCapitalLetter === word || AllLowerCaseLetter === word || FirstCapitalLetter === word) return true; + + return false; +};