Write a method for the Linked List class which takes a number, k, as a parameter. Return the node’s value that is k from the end of the linked list.
Extend the linked list with these three different methods:
.kthFromEnd(k)(returns the node’s value that iskfrom the end of the linked list)
Input: a numberkused as a search value Output: the value of the nodekplaces from the end of the linked list
Edge case(s):
- An empty linked list (Throw error)
kis greater than nodes in the linked list. (Throw error)kis not a positive integer (Throw error)kis ‘1’ and linked list has only 1 node (Can handle)
Write tests to prove the following functionality:
