Write a function named add
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 list in proper ascending numerical order. 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.
var tail = { next: null };
var cell2 = { data: 45, next: tail };
var cell1 = { data: 12: next: cell2 };
var head = { next: cell1 };