Here the requirement is to compare both the array elements a(i) and b(i). And update the
If a[i]>b[i] , then a is awarded 1 point
If b[i]>a[i] , then b is awarded 1 point
object MyWizard extends App {
def compareTriplets(a:Array[Int],b:Array[Int]):Array[Int]= {
var aCount=0
var bCount=0
for(i<-0 to a.length-1){
for(j<-0 to b.length-1){
if(i==j) {
if(a(i)>b(i)){
aCount=aCount+1
}else if(a(i)<b(i)){
bCount=bCount+1
}
}
}
}
val c:Array[Int]=Array(aCount,bCount)
c
}
println(compareTriplets(Array(1,32,3),Array(453,2,1)))
}
array.mkString("[", ", ", "]")to get a nice string representation of your data. Or do not use Arrays*+ but rather a **List which is a more high level and idiomatic data structure in Scala. Also, I would recommend you to do not use mutability and loops, but higher-order functions or recursion. Also, if the result always has two elements do not return a collection. but a tuple. Also, it seems you are not that versed in Scala, I would recommend you to follow some tutorials.