본문 바로가기
알고리즘/Codewars

[Codewars] Is the string uppercase? (8 kyu) / JavaScript / Python

by fluss 2023. 3. 21.

https://www.codewars.com/kata/56cd44e1aa4ac7879200010b

 

DESCRIPTION:

Is the string uppercase?

Task

Create a method to see whether the string is ALL CAPS.

 

Examples (input -> output)

"c" -> False
"C" -> True
"hello I AM DONALD" -> False
"HELLO I AM DONALD" -> True
"ACSKLDFJSgSKLDFJSKLDFJ" -> False
"ACSKLDFJSGSKLDFJSKLDFJ" -> True

In this Kata, a string is said to be in ALL CAPS whenever it does not contain any lowercase letter so any string containing no letters at all is trivially considered to be in ALL CAPS.

 

코드

JavaScript 

String.prototype.isUpperCase = function() {
  return this.toString() === this.toUpperCase();
}

 

Python

def is_uppercase(inp):
    return inp == inp.upper()

댓글