Question: CODE IN ERLANG 8. Function getnth that takes a list and an int n and returns the nth element of the list, where the head

CODE IN ERLANG

CODE IN ERLANG 8. Function getnth that takes a list and an

8. Function getnth that takes a list and an int n and returns the nth element of the list, where the head of the list is the 1st element. You are only allowed to use list functions hd and tl in your solution - no other built-in functions are allowed. If the list is empty or n is invalid, return a tuple: {error, no_such_element} add the following test cases to the test file: getnth_1_test() -> {error, no_such_element} = lab05:getnth( I ), 2). getnth_2_test() -> {error, no_such_element} = lab05:getnth( ["hello", "there"), 3). getnth_3_test() -> {error, no_such_element} = labo5.getnth( ["hello", "there"), o). getnth_4_test() -> "there" = lab05:getnth( ["hello", "there"), 2). getnth_5_test() -> "there" = lab05:getnth( ["hello", "there", "where"), 2). getnth_6_test() -> "where" = lab05:getnth( ["hello", "there", "where"), 3). getnth_7_test() -> "where" = lab05:getnth( ["hello", "there", "where", "here"), 3). 8. Function getnth that takes a list and an int n and returns the nth element of the list, where the head of the list is the 1st element. You are only allowed to use list functions hd and tl in your solution - no other built-in functions are allowed. If the list is empty or n is invalid, return a tuple: {error, no_such_element} add the following test cases to the test file: getnth_1_test() -> {error, no_such_element} = lab05:getnth( I ), 2). getnth_2_test() -> {error, no_such_element} = lab05:getnth( ["hello", "there"), 3). getnth_3_test() -> {error, no_such_element} = labo5.getnth( ["hello", "there"), o). getnth_4_test() -> "there" = lab05:getnth( ["hello", "there"), 2). getnth_5_test() -> "there" = lab05:getnth( ["hello", "there", "where"), 2). getnth_6_test() -> "where" = lab05:getnth( ["hello", "there", "where"), 3). getnth_7_test() -> "where" = lab05:getnth( ["hello", "there", "where", "here"), 3)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!