Skip to content

Commit

Permalink
feat: helpers: toTitle (new), interval (accept interface)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabaie committed Feb 13, 2022
1 parent 63d5af2 commit 7b344a7
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func helpers() template.FuncMap {
"reverse": reverse,
"sub": sub,
"toLower": strings.ToLower,
"toTitle": strings.Title,
"toUpper": strings.ToUpper,
"words64": printBigIntAsUint64Slice,
}
Expand Down Expand Up @@ -106,13 +107,22 @@ func intBytes(i big.Int) []byte {
return i.Bytes()
}

func interval(begin, end int) []int {
l := end - begin
r := make([]int, l)
for i := 0; i < l; i++ {
r[i] = i + begin
func interval(begin, end interface{}) ([]int64, error) {
beginInt, err := toInt64(begin)
if err != nil {
return nil, err
}
endInt, err := toInt64(end)
if err != nil {
return nil, err
}

l := endInt - beginInt
r := make([]int64, l)
for i := int64(0); i < l; i++ {
r[i] = i + beginInt
}
return r
return r, nil
}

// Adopted from https://stackoverflow.com/a/50487104/5116581
Expand Down

0 comments on commit 7b344a7

Please sign in to comment.