aprendago icon indicating copy to clipboard operation
aprendago copied to clipboard

Exercício: Capítulo 9, Exercício 5 (Nível: 4)

Open vkorbes opened this issue 4 years ago • 19 comments

Exercício: Capítulo 9, Exercício 5 (Nível: 4)

Link para o vídeo:

Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!

vkorbes avatar Sep 30 '20 17:09 vkorbes

https://play.golang.org/p/9NDIac0sqKU

diegoparra avatar Oct 07 '20 20:10 diegoparra

https://play.golang.org/p/BL3cK0afGqu

andersoncleyson avatar Oct 09 '20 21:10 andersoncleyson

package main 

import("fmt")

func main(){
  
  x := []int{42,43,44,45,46,47,48,49,50,51}
  y := append(x[:3],x[6:]...)
  fmt.Println(y)
}

haystem avatar Nov 20 '20 03:11 haystem

https://play.golang.org/p/voFHHlAsMXL

package main

import (
	"fmt"
)

func main() {
	fmt.Printf(`- Comece com essa slice:
    	- x := []int{42, 43, 44, 45, 46, 47, 48, 49, 50, 51}`)
	fmt.Println("")
	fmt.Println("")

	x := []int{42, 43, 44, 45, 46, 47, 48, 49, 50, 51}

	fmt.Println("Utilizando slicing e append, crie uma slice y que contenha os valores:")
	fmt.Println("[42, 43, 44, 48, 49, 50, 51]")
	fmt.Println("")
	z := x[:3]
	b := x[6:]
	y := append(z, b...)
	fmt.Println("FINAL:", y)

}

Output

- Comece com essa slice:
    	- x := []int{42, 43, 44, 45, 46, 47, 48, 49, 50, 51}

Utilizando slicing e append, crie uma slice y que contenha os valores:
[42, 43, 44, 48, 49, 50, 51]

FINAL: [42 43 44 48 49 50 51]

Program exited.

Tres maneiras legais de fazer

	z := x[:3]
	b := x[6:]
	y := append(z, b...)

or

y := append(x[:3], x[6:]...)

or

x = append(x[:3], x[len(x)-4:]...)

an4kein avatar Feb 18 '21 14:02 an4kein

package main 

import("fmt")

func main(){
  
  x := []int{42,43,44,45,46,47,48,49,50,51}
  y := append(x[:3],x[6:]...)
  fmt.Println(y)
}

Achei interessante essa forma de declarar, economiza mais linhas:

y := append(x[:3], x[6:]...)

o que ela fez no video, tbm achei maneiro

x = append(x[:3], x[len(x)-4:]...)

an4kein avatar Feb 18 '21 14:02 an4kein

My solution:

package main

import "fmt"

func main() {
	x := []int{42, 43, 44, 45, 46, 47, 48, 49, 50, 51}

	y := append(x[:3], x[6:]...)

	fmt.Println(y)
}

alansantosmg avatar Apr 21 '21 14:04 alansantosmg

https://play.golang.org/p/UWu6oei1UtI

Lucasmirandar avatar Jun 09 '21 23:06 Lucasmirandar

5. Começando com a seguinte slice:

x := []int{42, 43, 44, 45, 46, 47, 48, 49, 50, 51}

  • Utilizando slicing e append, crie uma slice y que contenha os valores: [42, 43, 44, 48, 49, 50, 51]
package main

import "fmt"

func main() {
	x := []int{42, 43, 44, 45, 46, 47, 48, 49, 50, 51}
	x = append(x[:3], x[6:]...)

	fmt.Printf("slice: %v\n", x)
}

Resultado:

slice: [42 43 44 48 49 50 51]

Resolução do Exercício


JPauloMoura avatar Aug 09 '21 01:08 JPauloMoura

package main

import "fmt"

func main() {
	x := []int{42, 43, 44, 45, 46, 47, 48, 49, 50, 51}

	y := []int{}

	y = append(y, x[:3]...)

	y = append(y, x[6:]...)

	fmt.Println(y)
}

andersoncleyson avatar Sep 13 '21 11:09 andersoncleyson

package main

import (
	"fmt"
)

func main() {
	x := []int{42, 43, 44, 45, 46, 47, 48, 49, 50, 51}
	y := append(x[:3],x[6:]...)
	fmt.Println(y)
}

tomashugo avatar Oct 10 '21 15:10 tomashugo

https://go.dev/play/p/EOjG6_kW697

viniciussanchez avatar Mar 17 '22 16:03 viniciussanchez

https://go.dev/play/p/-HF9KTowBKb

AlissonAp avatar Apr 15 '22 01:04 AlissonAp

Cap. 9 – Exercícios: Nível #4 – 5 https://go.dev/play/p/eTjb6h9cEUT

image

wfrsilva avatar May 27 '22 02:05 wfrsilva

func main() { x := []int{42, 43, 44, 45, 46, 47, 48, 49, 50, 51} y := []int{} y = append(x[:3], x[6:]...) fmt.Println(y) }

M3L1M avatar Feb 13 '23 23:02 M3L1M

package main

import (
	"fmt"
)

func main() {

	x := []int{42, 43, 44, 45, 46, 47, 48, 49, 50, 51}

	y := append(x[0:3], x[6:]...)

	fmt.Println(y)

}

adelsonsljunior avatar May 13 '23 22:05 adelsonsljunior

https://go.dev/play/p/yiNf1da24BS

DominMFD avatar May 15 '24 13:05 DominMFD

// You can edit this code!
// Click here and start typing.
package main

import "fmt"

//- Comece com essa slice:
//    - x := []int{42, 43, 44, 45, 46, 47, 48, 49, 50, 51}
//- Utilizando slicing e append, crie uma slice y que contenha os valores:
//    - [42, 43, 44, 48, 49, 50, 51]

func main() {
	x := []int{42, 43, 44, 45, 46, 47, 48, 49, 50, 51}
	leftSlice := x[:3]
	size := len(x)
	rightSlice := x[size-4:]
	newSlice := append(leftSlice, rightSlice...)

	fmt.Println(leftSlice)
	fmt.Println(size)
	fmt.Println(newSlice)

}

thiagoCalazans-dev avatar May 18 '24 12:05 thiagoCalazans-dev

Esse exercício me pareceu um pouco ambíguo. Pelo meu entendimento a ideia é começar com o slice x e criar um slice y com o resultado esperado, mas ao mesmo tempo preservando o slice x original.

Resultado esperado dos dois slices: [42, 43, 44, 45, 46, 47, 48, 49, 50, 51] [42, 43, 44, 48, 49, 50, 51]

Solução no meu entendimento

murilo-kendjy avatar May 25 '24 19:05 murilo-kendjy

https://go.dev/play/p/iP6trhNztnY

Vitor-Zen avatar Jul 04 '24 15:07 Vitor-Zen