👨‍💻
Tantangan Coding
  • Codewars
    • 08-01-2022
      • Cek IsUpperCase
  • Codewars
    • 08-01-2022
      • Mumbling Problem
Powered by GitBook
On this page
  • Problem
  • Solution
  • Best Solution

Was this helpful?

  1. Codewars
  2. 08-01-2022

Cek IsUpperCase

Previous08-01-2022NextCodewars

Last updated 3 years ago

Was this helpful?

8 kyu

x menit

Aku belajar tanpa pake libs

Problem

MyString("ABCDEFGHIJKLMNOPQRSTUVWXYz").IsUpperCase()
// false

MyString("WHAT DOES THE FOX SAY").IsUpperCase()
// true

Solution

type MyString string

func (s MyString) IsUpperCase() bool {
	res := false

	for _, v := range s {
		if string(v) == " " {
			continue
		}

		if v >= 'A' && v <= 'Z' {
			res = true
		} else {
			return false
		}
	}

	return res
}

Best Solution

import "strings"

type MyString string

func (s MyString) IsUpperCase() bool {
  return string(s) == strings.ToUpper(string(s))
}
💡
🕐
✏️