Splitting slices in half

Report a typo

Emma has created a function splitSlice(), which takes a slice of integers and splits it in half:

func splitSlice(slice []int) ([]int, []int) {
    half := len(slice) / 2
    return slice[:half], slice[half:]
}

Emma now wants to make splitSlice() a generic function that can take a slice of any data type, and then instantiate it within the main function, passing the stringSlice and floatSlice variables to it! Can you help her do so?

Sample Input 1:

Go JetBrains Hyperskill AmongUs
3.1416 1.618 2.718 0.01

Sample Output 1:

[Go JetBrains] [Hyperskill AmongUs]
[3.1416 1.618] [2.718 0.01]
Write a program in Go
package main

import "fmt"

const splitIndex = 2

// make splitSlice() a generic function that can take 'any' data type!
func splitSlice[? ?](? []?) ([]?, []?) {
half := len(s) / splitIndex
return s[:half], s[half:]
}

func main() {
// Do not change the code block below:
var str1, str2, str3, str4 string
fmt.Scanln(&str1, &str2, &str3, &str4)

var num1, num2, num3, num4 float64
fmt.Scanln(&num1, &num2, &num3, &num4)

stringSlice := []string{str1, str2, str3, str4}
floatSlice := []float64{num1, num2, num3, num4}

// Instantiate splitSlice() on the slice1, slice2, slice3 and slice4 variables below:
slice1, slice2 := ?
slice3, slice4 := ?

// Output the split slices:
fmt.Println(slice1, slice2)
fmt.Println(slice3, slice4)
}
___

Create a free account to access the full topic