Guest User

Untitled

a guest
Jun 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. function pair(a, b) {
  2. return function (selector) {
  3. if (selector) {
  4. return a;
  5. }
  6. return b;
  7. }
  8. }
  9.  
  10. function first(p) {
  11. if (p) {
  12. return p(true);
  13. }
  14. }
  15.  
  16. function remaining(p) {
  17. if (p) {
  18. return p(false);
  19. }
  20. }
  21.  
  22. function enqueue(element, p) {
  23. return pair(element, p);
  24. }
  25.  
  26. function get(nth, q) {
  27. if (nth === 0) {
  28. return first(q);
  29. }
  30. return get(nth - 1, remaining(q));
  31. }
  32.  
  33. console.log(get(2, enqueue(3, enqueue(2, enqueue(1)))));
Add Comment
Please, Sign In to add comment