Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started