↓ Skip to main content
Go

Pangram

·1 min

I wrote my first program for Pangram in JS here and attempted few variations to optimize the readability and execution time. This time the code challenge was in Golang and it was satisfying attempt to do in first try.

Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, “every letter”) is a sentence using every letter of the alphabet at least once. The best known English pangram is:

The quick brown fox jumps over the lazy dog.

package pangram

import "strings"

// Alphabets all the characters.
const Alphabets string = "abcdefghijklmnopqrstuvqxyz"

// IsPangram checks for pangram in the inputs string.
func IsPangram(in string) bool {
    in = strings.ToLower(strings.TrimSpace(in))
    if in == "" {
        return false
    }

    for _, v := range Alphabets {
        if strings.IndexRune(in, v) < 0 {
            return false
        }
    }
    return true
}

I could have simplified it further by instead of having the const Alphabets just loop through rune 'a' to 'z'.

The code is simple enough to go through, where I check in for the index of all the runes in the string Alphabets and if any one is not found, it is not a PANGRAM.

– THE - END –

Author
Samarthya
Engineer, learner, tinkerer. This is my trophy shelf of everyday work and leisure.

Related

Nil Interface

·2 mins
An interface in Golang is a set of methods and a type. What is the purpose of Nil interface in GO-lang A nil interface value holds neither value nor concrete type.

Metric Beat

All right, its been a busy week and finally some time at hand to write about something I have been doing. Mostly I am working on ELK stack these days, securing, validating, data analytics etc. Today, had the opportunity to go the Secure Elastic way, by enabling the TLS for secure communication within Nodes (Elastic cluster) and finally setup a Metric beat to get the status of the node.