Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having a hard time with Scala syntax. I've included the tests that this needs to pass. If you could comment and walk through your

I'm having a hard time with Scala syntax. I've included the tests that this needs to pass. If you could comment and walk through your code it would be much appreciated.

image text in transcribed

//BEGIN TEST /* Define functions for the tests */ val f1: Int => Int = (x) => (x+10) val f2: Int => Int = (x) => (-2*x) def f3(x: Int): Int = x*x val f4: Int => Int = (x) => { if (x

/* Some test cases */ testWithMessage(!isOddFunction(f1, 10), "1") testWithMessage(isOddFunction(f2, 100), "2") testWithMessage(!isOddFunction(f3, 100), "3") testWithMessage(isOddFunction(f4, 8), "4") testWithMessage(!isOddFunction(f4, 15), "5") passed(5) //END TEST

A function f:7 Z over integers is a odd function if for all numbers x EZ, f(-x) = -f(x). As an example f(x) = 5x is an odd function. However, f(x) = x2 is not. Write a scala function isOddFunction(f, n) that checks if f(-2) = -f(z) for every number z within the range 1, ... , n. The function should return true if f is indeed an odd function and false otherwise. You may use a for loop for this problem. HM 1 def isOddFunction(f: Int => Int, n: Int): Boolean = { ??? // YOUR CODE HERE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions