Write a function named push
that takes an argument named list
, which is the head cell of a linked list, and an argument named data
, which is a number, and creates a linked list cell containing a property named data with that value, and adds it to the beginning of the list. Return list
at the bottom of your function. Code to construct an example linked list in the form used in the tests is given below. Note that list
where it appears in the test output shows up in all cases in the form your function changed it into.
var tail = { next: null };
var cell2 = { data: 12, next: tail };
var cell1 = { data: 45: next: cell2 };
var head = { next: cell1 };