Giter Club home page Giter Club logo

Comments (6)

dsmello avatar dsmello commented on July 21, 2024

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

from aprendago.

diegoparra avatar diegoparra commented on July 21, 2024

Achei simples, só não consigo visualizar muito seu uso no dia a dia, talvez no decorrer do curso faça mais sentido.

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

from aprendago.

an4kein avatar an4kein commented on July 21, 2024

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

package main
//- Crie e utilize uma função anônima.
import "fmt"

func main() {
	func() {
		fmt.Println("func anonymous")
	}()
	louco := func(x int) int {
		return x
	}
	fmt.Println("Vamos brincar com essa func anon, demonstra esse valor:", louco(10))

}

Output

func anonymous
Vamos brincar com essa func anon, demonstra esse valor: 10

Program exited.

from aprendago.

alansantosmg avatar alansantosmg commented on July 21, 2024

Minha solução. Calculadora de emprestimos com juros compostos usando somente funções anonimas. Usei pra tudo, mas acho que elas seriam uteis para calculos simples, conversões.

/*
- Crie e utilize uma função anônima
*/

// Calculadora de juros compostos hardcoded

package main

import (
	"fmt"
	"math"
)

func main() {

	montante := 1000.0
	taxaJuros := 5
	prazo := 12

	// anonymous function converte taxa para float e percentual
	jurosMes := func(t int) (j float64) {
		j = float64(t) / 100
		return
	}(taxaJuros)

	// converte prazo de int para float
	fPrazo := func(p int) (pf float64) {
		pf = float64(p)
		return
	}(prazo)

	//calcula emprestimo
	totalPago := func(montante, fPrazo, jurosMes float64) (total float64) {
		total = montante * math.Pow((1+jurosMes), fPrazo)
		return
	}(montante, fPrazo, jurosMes)

	func(montante float64, taxaJuros int, prazo int, totalPago float64) {
		fmt.Printf("Valor emprestado R$: %0.2f\n", montante)
		fmt.Printf("Taxa de juros: %d%% ao mês.\n", taxaJuros)
		fmt.Printf("Prazo: %d meses.\n", prazo)
		fmt.Printf("Total pago ao final do empréstimo: R$ %0.2f\n", totalPago)
	}(montante, taxaJuros, prazo, totalPago)

}

from aprendago.

wfrsilva avatar wfrsilva commented on July 21, 2024

Cap. 13 – Exercícios: Nível #6 – 6
https://go.dev/play/p/IJKPOcV7uk4

image

from aprendago.

Harsgaard avatar Harsgaard commented on July 21, 2024

https://go.dev/play/p/80atnU8B5qm

from aprendago.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.