Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

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

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

Students also viewed these Databases questions