Write an Elixir program that contains a module called Hw.Lists , with the following functions: 1.- swapper: Takes a list
Posted: Tue Jul 12, 2022 8:19 am
Write an Elixir program that contains a modulecalled Hw.Lists , with the followingfunctions:
1.- swapper: Takes a list, and two elements Aand B as arguments. It will return a new list with any appearanceof A substituted for B, and vice versa. Any other elements are keptin the same place
2.- invert_pairs: Takes a list of tuples asargument. All tuples must have only two elements. Returns a newlist of tuples, where each tuple has the elements in inverseorder:
3.- deep_reverse: Takes a list asarguments. The list may contain nested lists. It will returnanother list, where the elements are in reverse order. The elementsin any nested list must also reverse their order. You can NOT usethe built in function for reverse:
4.- mean: Takes a list of numbers as argument.Computes the average of its values, as the sum of all of themdivided by the number of elements in the list
5.- std_dev: Takes a list of numbers asargument. Computes the standard deviation, using the followingformula:
***You can create any additional functions to help insolving the problems. However, you can NOT use built in functionsthat already perform the same task.***
σ=N∑(xi−μ)2
1.- swapper: Takes a list, and two elements Aand B as arguments. It will return a new list with any appearanceof A substituted for B, and vice versa. Any other elements are keptin the same place
2.- invert_pairs: Takes a list of tuples asargument. All tuples must have only two elements. Returns a newlist of tuples, where each tuple has the elements in inverseorder:
3.- deep_reverse: Takes a list asarguments. The list may contain nested lists. It will returnanother list, where the elements are in reverse order. The elementsin any nested list must also reverse their order. You can NOT usethe built in function for reverse:
4.- mean: Takes a list of numbers as argument.Computes the average of its values, as the sum of all of themdivided by the number of elements in the list
5.- std_dev: Takes a list of numbers asargument. Computes the standard deviation, using the followingformula:
***You can create any additional functions to help insolving the problems. However, you can NOT use built in functionsthat already perform the same task.***
σ=N∑(xi−μ)2