Skip to content

Instantly share code, notes, and snippets.

@aceakash
Created May 18, 2022 17:25
Show Gist options
  • Save aceakash/b8657b20ab34780e01b263a16429d0a9 to your computer and use it in GitHub Desktop.
Save aceakash/b8657b20ab34780e01b263a16429d0a9 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
)
func main() {
myList := []int64{1,2,3,4,5,6,7,8,9}
// yay I'm getting a new list with the results
newList := Execute(myList)
fmt.Println(newList)
// noooo why did you change the list I sent you?!
fmt.Println(newList)
}
func Execute(input []int64) []int64 {
for i, value := range input {
squareRootFromValue := math.Sqrt(float64(value))
if squareRootFromValue - math.Floor(squareRootFromValue) == 0 {
input[i] = int64(squareRootFromValue)
} else {
input[i] = value*value
}
}
return input
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment