Skip to content

Latest commit

 

History

History
29 lines (24 loc) · 545 Bytes

golang_mask_function.md

File metadata and controls

29 lines (24 loc) · 545 Bytes

Golang simple mask function

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	fmt.Println(Mask(0.75, "085662772142", "*"))
}

func Mask(howMany float64, content, masker string) string {
	if len(content) <= 0 {
		return ""
	}
	sub := content[0 : len(content)-int(math.Floor(float64(len(content))*howMany))]
	masker = strings.Repeat(masker, int(math.Floor(float64(len(content))*howMany))-1)
	return strings.Join([]string{sub, masker, content[len(content)-1 : len(content)]}, "")
}

Output:

085********2