Created
October 28, 2016 23:48
-
-
Save marcoslhc/93f8e5e33913d794f00c3df8476aa8f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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