Skip to content

Instantly share code, notes, and snippets.

@marcoslhc
Created October 28, 2016 23:48
Show Gist options
  • Select an option

  • Save marcoslhc/93f8e5e33913d794f00c3df8476aa8f2 to your computer and use it in GitHub Desktop.

Select an option

Save marcoslhc/93f8e5e33913d794f00c3df8476aa8f2 to your computer and use it in GitHub Desktop.
function isArray(elm) {
return ('object' === typeof elm && elm.length >= 0);
}
function cons(elm1, elm2) {
if (!isArray(elm1)) elm1 = [elm1];
return elm1.concat(elm2);
}
function car(arr) {
if (isArray(arr)) return arr[0];
return arr
}
function cdr(arr) {
if(isArray(arr)) return arr.slice(1);
return [arr]
}
function cadr(arr) {
return cdr(car(arr));
}
function cdar(arr) {
return cdr(car(arr));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment