Ding-Log
  • Ding Blog
  • Life
    • My Tool Box
  • Golang
    • Basic
      • Go语言学习笔记
        • Go语言 Channel
        • Go语言 goroutine
        • Go语言 如何写Godoc
        • Go语言panic, recover
        • Go语言的Defer函数
        • Go语言的闭包
        • Go语言接口(Golang - Interface)
        • Go语言的面向对象
      • Go语言爬虫
        • Go语言爬虫 - 广度优先算法
      • Map
    • Web
      • Example to handle GET and POST request in Golang
    • Exercism
      • Isogram
      • ETL
      • Accumulate
      • Scrabble Score
  • SAP
    • SAPUI5&Fiori
      • How to prepare C_FIORDEV_20 SAP Certified Development Associate — SAP Fiori Application Developer
      • SAPUI5 sap.ui.define and sap.ui.require
      • SAPUI5 Models and Binding
      • SAPUI5 MVC Walkthrough
    • ABAP
      • Working with Internal Tables
      • 关于使用内部表的时候的一些注意事项
      • Error Handling
  • Log
Powered by GitBook
On this page
  • Introduction
  • Running the tests
  • Further information
  • Source
  • Submitting Incomplete Solutions
  • Point

Was this helpful?

  1. Golang
  2. Exercism

Isogram

Introduction

Determine if a word or phrase is an isogram.

An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times.

Examples of isograms:

  • lumberjacks

  • background

  • downstream

  • six-year-old

The word isograms, however, is not an isogram, because the s repeats.

Running the tests

To run the tests run the command go test from within the exercise directory.

If the test suite contains benchmarks, you can run these with the --benchand --benchmem flags:

go test -v --bench . --benchmem

Keep in mind that each reviewer will run benchmarks on a different machine, with different specs, so the results from these benchmark tests may vary.

Further information

Source

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

package isogram

import "strings"

func noSpaceorHyphens(s string) string {
	rep := strings.NewReplacer(" ", "", "-", "")
	return rep.Replace(s)
}

// IsIsogram is a function to check string duplicate
func IsIsogram(input string) bool {
	input = noSpaceorHyphens(input)
	input = strings.ToLower(input)
	temp := map[string]struct{}{}
	for _, r := range input {
		if _, ok := temp[string(r)]; !ok {
			temp[string(r)] = struct{}{}
		} else {
			return false
		}
	}
	return true
}

Point

  • Use the feature of Map

i, ok := m["route"]

In this statement, the first value (i) is assigned the value stored under the key "route". If that key doesn't exist, i is the value type's zero value (0). The second value (ok) is a bool that is true if the key exists in the map, and false if not.

PreviousExercismNextETL

Last updated 6 years ago

Was this helpful?

For more detailed information about the Go track, including how to get help if you're having trouble, please visit the exercism.io .

Wikipedia

Go language page
https://en.wikipedia.org/wiki/Isogram