last function (#17)

* last function

* fix CI

Co-authored-by: Ruidy <rnemausat@newstore.com>
This commit is contained in:
Ruidy 2022-03-21 13:04:30 -04:00 committed by GitHub
parent edb3c09e43
commit fb517f3b04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 14 deletions

5
.github/FUNDING.yml vendored
View file

@ -1,4 +1 @@
# These are supported funding model platforms
github: rjNemo # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
github: rjNemo

View file

@ -12,12 +12,12 @@ jobs:
with:
go-version: '1.18'
- name: Run tests with coverage
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
run: go test -coverprofile=coverage.out -covermode=count ./...
- uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
files: ./coverage.out # optional
flags: unittests # optional
name: codecov-umbrella # optional
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.out
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
verbose: true

View file

@ -1,6 +1,8 @@
FROM golang:1.18-alpine
ENV CGO_ENABLED 0
ENV GOOS linux
RUN apk update --no-cache
WORKDIR /lib
@ -9,3 +11,4 @@ COPY go.* ./
RUN go mod download
COPY . ./

View file

@ -1,7 +1,7 @@
TEST = "go test ./... -coverpkg=./... -coverprofile coverage.out -covermode=atomic; go tool cover -func coverage.out; rm coverage.out"
TEST = "go test ./... -coverpkg=./... -coverprofile coverage.out -covermode=count; go tool cover -func coverage.out; rm coverage.out"
build:
docker build . -t underscore:latest
docker build -t underscore:latest .
test: build
docker run --name underscore --rm -i -t underscore sh -c $(TEST)

2
docs/themes/compose vendored

@ -1 +1 @@
Subproject commit 362af2409158972008f1dff8ee5e887d6ce88257
Subproject commit 94194f5630e67d3fdbc5d4ae39ac027b0455d29a

7
last.go Normal file
View file

@ -0,0 +1,7 @@
package underscore
// Last returns the last element of the slice
func Last[T any](values []T) T {
n := len(values)
return values[n-1]
}

15
last_test.go Normal file
View file

@ -0,0 +1,15 @@
package underscore_test
import (
"testing"
"github.com/stretchr/testify/assert"
u "github.com/rjNemo/underscore"
)
func TestLast(t *testing.T) {
nums := []int{1, 9, 2, 8, 3, 7, 4, 6, 5}
want := 5
assert.Equal(t, want, u.Last(nums))
}