addAt(index,element)
method that adds an element at a given index. Return false if an element could not be added.
Note: Remember to check if the given index is a negative or is longer than the length of the linked list.
addAt
method should reassign head
to the new node when the given index is 0.
testString: assert((function(){var test = new LinkedList(); test.add('cat'); test.add('dog'); test.addAt(0,'cat'); return test.head().element === 'cat'}()), 'Your addAt
method should reassign head
to the new node when the given index is 0.');
- text: Your addAt
method should increase the length of the linked list by one for each new node added to the linked list.
testString: assert((function(){var test = new LinkedList(); test.add('cat'); test.add('dog'); test.addAt(0,'cat'); return test.size() === 3}()), 'Your addAt
method should increase the length of the linked list by one for each new node added to the linked list.');
- text: Your addAt
method should return false
if a node was unable to be added.
testString: assert((function(){var test = new LinkedList(); test.add('cat'); test.add('dog'); return (test.addAt(4,'cat') === false); }()), 'Your addAt
method should return false
if a node was unable to be added.');
```