Reverse works, but not prettily.
This commit is contained in:
parent
c5008cdb5d
commit
c34a0f391b
|
@ -23,21 +23,21 @@ map = (lst, iteratee, context, count = 0) ->
|
||||||
cons product, rest
|
cons product, rest
|
||||||
|
|
||||||
rmap = (lst, iteratee, context, count = 0) ->
|
rmap = (lst, iteratee, context, count = 0) ->
|
||||||
return nil if nilp lst
|
ptr = lst
|
||||||
rest = (if (nilp cdr lst) then nil else
|
ret = cons()
|
||||||
map((cdr lst), iteratee, context, count + 1))
|
while not nilp ptr
|
||||||
product = iteratee.call(context, (car lst), count, lst)
|
ret = cons (car ptr), ret
|
||||||
cons rest, product
|
ptr = cdr ptr
|
||||||
|
ret
|
||||||
|
|
||||||
reverse = (lst) -> rmap lst, (i) -> i
|
reverse = (lst) -> rmap lst, (i) -> i
|
||||||
|
|
||||||
filter = (lst, iteratee, context) ->
|
filter = (lst, iteratee, context) ->
|
||||||
return nil if nilp lst
|
return nil if nilp lst
|
||||||
if iteratee.call(context, (car lst), lst)
|
if iteratee.call(context, (car lst), lst)
|
||||||
cons (car lst), filter (cdr lst), iteratee, context
|
cons (car lst), (filter (cdr lst), iteratee, context)
|
||||||
else
|
else
|
||||||
filter (cdr list), iteratee, context
|
filter (cdr lst), iteratee, context
|
||||||
|
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
reduce: reduce
|
reduce: reduce
|
||||||
|
|
Loading…
Reference in New Issue