I am new to Scala. In the code below I am trying to return value
from classing_summary function but I am facing trouble using the
yield function. Here, I want to yield multiple values from inside the nested for loop.
Currently it does not return anything.
How to fix the code?
def classing_summary(arr: Array[(Double, Int)]) = {
var value = 0.0
var freq = 1
var prevValue = Double.MinValue
var bin = 1
var classSize = 0.0
var size = arr.length
val tCount = arr.map{case (x,y) => y}.sum
val output = for(i <- 0 until size) yield
{
value = arr(i)._1
freq = arr(i)._2
if(freq/tCount >= 0.05)
{
for(j <- 0 until freq) yield
{
classSize += 1/tCount;
(value,bin,classSize);
}
classSize = 0.0
bin +=1
}
else
{
for(j <- 0 until freq ) yield
{
classSize += 1/tCount;
(value,bin,classSize);
}
if(classSize >= 0.05)
{
classSize = 0.0;
bin += 1;
}
}
}
output.toArray
}