Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

add an element to the front of an input list in javascript

/* List structure: a nested set of objects. NOT an array.
Each object holds reference to its successor in the object chain. */

// Add a value to the front of a list (object chain)
// Use the list itself as input
function prepend(value, list){
  return {value, rest:list};
};

console.log(prepend(10, prepend(20, null)));
// → {value: 10, rest: {value: 20, rest: null}}
Comment

PREVIOUS NEXT
Code Example
Javascript :: add 2 microseconds to Date() js 
Javascript :: how to detect js module was required 
Javascript :: angular amber theme 
Javascript :: how to only accept email in the format of name@domain.com js 
Javascript :: Configure morgan so that it also shows the data sent in HTTP POST requests: 
Javascript :: express get request origin 
Javascript :: byte to kb javascript 
Javascript :: sin in javascript 
Javascript :: remove tr having delete icon inside jquery 
Javascript :: js inner text 
Javascript :: javascript before reload page alert 
Javascript :: json parse stringified array 
Javascript :: javascript enumerate 
Javascript :: jquery input change while typing 
Javascript :: javascript compare 2 thresholds color 
Javascript :: js add delay with promises 
Javascript :: newtonsoft json deserialize c# example 
Javascript :: javascript regex check if string is empty 
Javascript :: node js get files in dir 
Javascript :: vue call method after delay 
Javascript :: show console chrome mac 
Javascript :: mongoose pull each 
Javascript :: javascript for border color 
Javascript :: update node mac 
Javascript :: eslint no-param-reassign 
Javascript :: js get meta content 
Javascript :: javascript find unique values in array 
Javascript :: refresh page js 
Javascript :: input pattern for np whitespaces at the end or beginning 
Javascript :: javascript date to utc format 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =