Skip to content

potproject/go-iseven

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-iseven

samuelmarina/is-even Compatibility Code for Golang.

Support Range: 0 - 9,999

About

I thought the is-even library was so great that I tried to port it to the Go language. However, I have only one complaint about this code. it is very hard to write the code by hand. Therefore, I decided that a great solution would be to generate the code automatically!

Note: The range can be changed, but on my machine, if there was too much code, the build was too slow to work...

Example

// go generate
go generate

generating file:iseven.go

package main

// Code generated by go-iseven-generator; DO NOT EDIT.
func IsEven(number string) bool {
	if number == "even" || number == "Even" || number == "eVen" || number == "evEn" || number == "eveN" || number == "EVen" || number == "EvEn" || number == "EveN" || number == "eVEn" || number == "eVeN" || number == "evEN" || number == "eVEN" || number == "EvEN" || number == "EVeN" || number == "EVEn" || number == "EVEN" {
		return true
	}
	if number == "0" || number == "zero" || number == "ZERO" || number == "Zero" {
		return true
	} else if number == "1" || number == "one" || number == "ONE" || number == "One" {
		return false
	} else if number == "2" || number == "two" || number == "TWO" || number == "Two" {
		return true
	} else if number == "3" || number == "three" || number == "THREE" || number == "Three" {
		return false
	} else if number == "4" || number == "four" || number == "FOUR" || number == "Four" {
		return true
	} else if number == "5" || number == "five" || number == "FIVE" || number == "Five" {
		return false
	} else if number == "6" || number == "six" || number == "SIX" || number == "Six" {
		return true
	} else if number == "7" || number == "seven" || number == "SEVEN" || number == "Seven" {
		return false
	} else if number == "8" || number == "eight" || number == "EIGHT" || number == "Eight" {
		return true
	} else if number == "9" || number == "nine" || number == "NINE" || number == "Nine" {
		return false
	} else if number == "10" || number == "ten" || number == "TEN" || number == "Ten" {
		return true
	} else if number == "11" || number == "eleven" || number == "ELEVEN" || number == "Eleven" {
		return false
	} else if number == "12" || number == "twelve" || number == "TWELVE" || number == "Twelve" {
		return true
	} else if number == "13" || number == "thirteen" || number == "THIRTEEN" || number == "Thirteen" {
		return false
	} else if number == "14" || number == "fourteen" || number == "FOURTEEN" || number == "Fourteen" {
		return true
	} else if number == "15" || number == "fifteen" || number == "FIFTEEN" || number == "Fifteen" {
		return false
	} else if number == "16" || number == "sixteen" || number == "SIXTEEN" || number == "Sixteen" {
		return true
	} else if number == "17" || number == "seventeen" || number == "SEVENTEEN" || number == "Seventeen" {
		return false
	} else if number == "18" || number == "eighteen" || number == "EIGHTEEN" || number == "Eighteen" {
		return true
	} else if number == "19" || number == "nineteen" || number == "NINETEEN" || number == "Nineteen" {
		return false
	} else if number == "20" || number == "twenty" || number == "TWENTY" || number == "Twenty" {
		return true
	} else if number == "21" || number == "twenty-one" || number == "TWENTY-ONE" || number == "Twenty-One" {
		return false
	} else if number == "22" || number == "twenty-two" || number == "TWENTY-TWO" || number == "Twenty-Two" {
		return true
	}
// more...

Return true if the number passed is even, hopefully...

// Extremely Slow!!
go run main.go iseven.go 1
>false
go run main.go iseven.go 2
>true
go run main.go iseven.go 10000
>false

LICENSE

MIT

About

is-even Compatibility Code for Golang.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages