Question:- Can anyone please help me to solve the below problem?
ListMapHigherOrder takes an array of string inputs args from command line. First convert the array of strings args to intList i.e a list of integers. Write a function isPerfectNumber which takes integer input and returns String output . It finds if a number is perfect and returns true if perfect else return false . A perfect number is a number whose sum factors(except for the number itself) is itself (like 6 = 1+2+3). Now write a higher order function myHigherOrderFunction which takes isPerfectNumber and intList as input and returns a List of Strings which contains the output if the number is perfect or not using map .
Code snippet:-
object ListMapHigherOrder{ def main(args :Array[String])
{
val intList :List[Int] = //write code to convert args to list of integers
def isPerfectNumber //write code to find is a number is perfect or not
}
def myHigherOrderFunction //complete the higher order function
}
println(myHigherOrderFunction(isPerfectNumber, intList))
}
}
Compile the program using:
scalac ListMapHigherOrder.scala
Execute the program to print the outputs:
scala ListMapHigherOrder.scala 3 6 7
Output will be: List(false, true, false)