Created
May 18, 2022 17:25
-
-
Save aceakash/b8657b20ab34780e01b263a16429d0a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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