Use the map and reduce functions of lecture 17 to implement

Use the map and reduce functions of lecture 17 to implement function maxSquareVal that determines the maximal square value of a list of integer numbers.

Example

(define maxSquareVal (lambda (l)

... ))

...

(maxSquareVal ’(-5 3 -7 -10 12 8 7)) --> 144

Solution

(define maxSquareVal
   (lambda (l)
       (let ((sqrl (map (lambda (x) (* x x)) l)))
           (reduce
               (lambda (x y)(if (>x y) x y))
               sqrl 0
           )
       )
   )
)

(maxSquareVal ’(-5 3 -7 -10 12 8 7))

/* sample output

144

*/

Use the map and reduce functions of lecture 17 to implement function maxSquareVal that determines the maximal square value of a list of integer numbers. Example

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site