Tutorial-4
Tutorial-4
Tutorial -4
Question:
1. Compare and contrast between function/method and higher order function/method.
2. Given the username as follows. Write a functional Java/Javascript code to find a username
called “salleh”. Display the name if found, otherwise, display a null.
String[] username = { "ali", "ahmad", "maria", "john", "derick", "salleh" };
3. With the use of lambda expression, modify the following code in Java to achieve the same
outcome.
class Joiner{
String join(String a, String b) { return a + b; }
}
Joiner joiner = new Joiner();
System.out.println( joiner.join(str1, str2) );
Discuss the outcome of the code execution. Review the source code by implementing
functional concept using Java/Javascript language.
5. Given the mathematical statement below. Explain how could currying technique be
applied.
f(20, 15) = 20 + 15
7. Consider the Membership class and List object comprising 4 membership objects. Write a
functional code to top up the membership points by 10. After increasing the membership
points, populate all membership objects in a new List. Display the old (note: immutable
list) and new List containing Membership points.
class Membership{
constructor(pt){ this.point = pt; }
}
const lst = [
new Membership(100),
new Membership(200),
new Membership(300),
new Membership(400),
];