public class Question3 { // This was good enough, though we could indeed argue about how faithful it is public static boolean elem (Object x, Object[] ys) { // elem x ys = foldr (||) False (map (x ==) ys) boolean[] mapXEqualsYs = new boolean[ys.length]; for (int i=0; i < ys.length; i++) { mapXEqualsYs[i] = x.equals(ys[i]); } boolean accum = false; for (int i=0; i < ys.length; i++) { accum = accum || mapXEqualsYs[i]; } return accum; } // programmer efficient! public static boolean elem2 (Object x, Object[] ys) { return java.util.Arrays.asList(ys).contains(x); } // time efficient! public static boolean elem3 (Object x, Object[] ys) { for(Object o: ys){ if (x.equals(o)) return true; } return false; } }