Last active
August 3, 2025 15:50
-
-
Save siberex/62d0a6a71f3b3e9471be9cf47c2c4556 to your computer and use it in GitHub Desktop.
Golang vs Node.js slices
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" | |
func main() { | |
a1 := []int{1, 2, 3, 4, 5} | |
a2 := a1[1:3] | |
a2 = append(a2, 10, 20) | |
fmt.Println(a1) // [1 2 3 10 20] | |
fmt.Println(a2) // [2 3 10 20] | |
// Slice is a reference until it is not, lol | |
// append beyond capacity will make a copy: | |
// a2 = append(a2, 10, 20, 30) | |
} |
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
let a1 = [1, 2, 3, 4, 5]; | |
let a2 = a1.slice(1, 3); | |
a2.push(10, 20); | |
console.log(a1); // [ 1, 2, 3, 4, 5 ] | |
console.log(a2); // [ 2, 3, 10, 20 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Src: https://x.com/siberex/status/1952024924521890263