Let's add a few more useful methods to our linked list class. Wouldn't it be useful if we could tell if our list was empty or not, as with our `Stack` and `Queue` classes?
We should also be able to find specific elements in our linked list. Traversing through data structures is something you'll want to get a lot of practice with! Let's create an `indexOf` method that takes an `element` as an argument, and returns that element's `index` in the linked list. If the element is not found in the linked list, return `-1`.
Let's also implement a method that does the opposite: an `elementAt` method that takes an `index` as an argument and returns the `element` at the given `index`. If no `element` is found, return `undefined`.
# --instructions--
Write an `isEmpty` method that checks if the linked list is empty, an `indexOf` method that returns the `index` of a given element, and an `elementAt` that returns an `element` at a given `index.`
# --hints--
Your `LinkedList` class should have an `isEmpty` method.
```js
assert(
(function () {
var test = new LinkedList();
return typeof test.isEmpty === 'function';
})()
);
```
Your `isEmpty` method should return `false` when there is at least one element in linked list.
```js
assert(
(function () {
var test = new LinkedList();
test.add('cat');
test.add('dog');
test.add('kitten');
return test.isEmpty() === false;
})()
);
```
Your `isEmpty` method should return `true` when there are no elements in linked list.
```js
assert(
(function () {
var test = new LinkedList();
return test.isEmpty() === true;
})()
);
```
Your `LinkedList` class should have an `indexOf` method.
```js
assert(
(function () {
var test = new LinkedList();
return typeof test.indexOf === 'function';
})()
);
```
Your `indexOf` method should return the index of a given element found in linked list.