This is why i like groovy. I follow an brazilian java list, and last week, a guy posted some logic exercices in java. One of them was:
Given an array of numbers, create a function that searches all instances of a given number an print the number of occurences of this number.
Another guy posted the answer in java:
public class Modulo{
public static int EncontraNumero(double[] vetor, double x, int count){
for (int i = 0; i < vetor.length; i++) {
if (vetor[i]== x)
count++;//calcula quantas vezes apareceu no vetor
}
return count;
}
public static void main(String[] args) {
double[] vet={2.3,5.7,9.65,3.33,4.10,5.23, 12.5, 12.5};
System.out.println(EncontraNumero(vet, 12.5, 0));
}
}
I created the same thing with groovy:
numbers = [2.3,5.7,9.65,3.33,4.10,5.23, 12.5, 12.5]
println numbers.findAll {it == 12.5 }.size
15 lines in 2. Wonderful
Olá, tudo bem?
Estou visitando os vizinhos, sabe como é, né? Mesmo sem ser programadora, gostei do groovy… rsrsrs (que mania as pessoas têm de sempre terem opinião pra tudo, mesmo que elas não entendam nada sobre o assunto, né?)
Falando de tecnologia ou não, acho que vou voltar. Dá uma passada no meu blog, vai que eu falo sobre algo que te interessa, né? rsrsrs
Implementaçãozinha porca também essa do cara.
[]s,
Lucas
Em python:
array = [2.3,5.7,9.65,3.33,4.10,5.23, 12.5, 12.5]
print len([i for i in array if i == 12.5])
😀