Quick actions

cmd+k|ctrl+k

Navigation

Languages

O(n)

Snippet info

Language

Go

Visibility

public

Author

max.suclatter

Created

2025-03-26T15:59:22.533245Z

Updated

2025-03-26T15:59:22.533245Z

package main

import (
    "fmt" 
    "time"
)

func findNemo[T comparable](a []T, ele T) {
    start := time.Now()
    operation := 0
    for _, e := range a {
        operation += 1
        if e == ele {
            
        }
    }
    elapsed := time.Since(start)
    fmt.Println("Elapsed time: ", elapsed)
    fmt.Println("Operations: ", operation)
}

func fillArray[T any](val T, size int) []T {
    result := make([]T, size)
    for i := range result {
        result[i] = val
    }
    return result
}

func main() {
    // findNemo([]int{1,2,3}, 2)
    // findNemo([]string{"hello", "world", "there", "nemo"}, "nemo")
    
    sample := fillArray("nemo", 100000)
    findNemo(sample, "nemo")
}
INFO