We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 3a19caf + 3677e3b commit 198512bCopy full SHA for 198512b
main.rkt
@@ -122,13 +122,13 @@
122
(rest lst)))
123
124
125
-; TODO optimize
126
(define (scanr proc lst)
127
- (foldr
128
- (λ (val acc)
129
- (append (list (proc val (first acc))) acc))
130
- (list (last lst))
131
- (init lst)))
+ (foldl
+ (λ (a acc)
+ (cond ((null? acc) (cons a acc))
+ (else (cons (proc a (car acc)) acc))))
+ '()
+ (reverse lst)))
132
133
134
(define (sorted? lst)
0 commit comments