diff options
| author | Paul Buetow <paul@buetow.org> | 2020-07-17 09:25:48 +0100 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2020-07-17 09:25:48 +0100 |
| commit | 224cff0a5113b1ea1a09fd48caf164e5690ec8a7 (patch) | |
| tree | 06faddeef4fdc4792b47576b332f28cea0bacbbb /ds/arraylist.go | |
| parent | 8f291992bdd98bd7ca6eefe084790e56d00833a8 (diff) | |
refactor
Diffstat (limited to 'ds/arraylist.go')
| -rw-r--r-- | ds/arraylist.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/ds/arraylist.go b/ds/arraylist.go new file mode 100644 index 0000000..65c42ef --- /dev/null +++ b/ds/arraylist.go @@ -0,0 +1,37 @@ +package ds + +import ( + "fmt" + "strings" +) + +type ArrayList []Comparer + +func (a ArrayList) FirstN(n int) string { + var sb strings.Builder + j := n + + length := len(a) + if j > length { + j = length + } + + for i := 0; i < j; i++ { + fmt.Fprintf(&sb, "%v ", a[i]) + } + + if j < length { + fmt.Fprintf(&sb, "... ") + } + + return sb.String() +} + +func (a ArrayList) Sorted() bool { + for i := len(a) - 1; i > 0; i-- { + if a[i].Lower(a[i-1]) { + return false + } + } + return true +} |
