solution by golang
\nfunc findClosestElements(arr []int, k int, x int) []int {\n    for len(arr) > k {\n        if abs(arr[0] - x) > abs(arr[len(arr) - 1] - x) {\n            arr 
```\nfunc findClosestElements(arr []int, k int, x int) []int {\n    for len(arr) > k {\n        if abs(arr[0] - x) > abs(arr[len(arr) - 1] - x) {\n            arr = arr[1:]\n        } else {\n            arr = arr[:len(arr)-1]\n        }\n    }\n    \n    return arr\n}\n\nfunc abs(a int) int {\n    if a < 0 {\n        return -a\n    }\n    return a\n}\n```
['Go']