-1

By using trianglecount from GraphX, I retrieve the following array:

Array[(org.apache.spark.graphx.VertexId, Int)] = Array((1,1), (3,1), (2,1))

I'm trying to find a way to sum the second value of each element in the array. Thus the 1's in this example.

I haven't been able to find a method how to do this.

  • 1
    You'll do much better if you make an attempt and post what you have. No one can tell if you don't know Scala or are just too lazy from this question. – duffymo Jun 29 '15 at 11:17
  • Understood. Had been busy with this for quite a while some days ago, so couldn't remember what I'd tried. Definitely get your point. Thanks – Ivo Van de Grift Jun 29 '15 at 13:57

1 Answers1

4
scala> val res = Array((1,1), (3,1), (2,1))
res: Array[(Int, Int)] = Array((1,1), (3,1), (2,1))

scala> res.map(_._2).sum
res7: Int = 3

or in one operation:

scala> res.foldLeft(0){case (acc, (k,v)) => acc +v }
res8: Int = 3
Nikita
  • 4,435
  • 3
  • 24
  • 44