help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: count char in string [The Emacs Challenge Competition - round 2, wit


From: Benjamín Buccianti
Subject: Re: count char in string [The Emacs Challenge Competition - round 2, with fallout]
Date: Wed, 28 Oct 2020 22:46:42 -0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> round 2:
>
> Very simple: we are looking for a function that returns the number of
> occurrences of a char in a string.
>
My solution!

(defun count-char-in-string (the-char str)
  (seq-reduce (lambda (counter next)
                (+ counter (if (eq the-char next) 1 0)))
              str
              0))

I really like this kind of things! Keep doing it! I learn a lot from other's 
answers.

Cheers!




reply via email to

[Prev in Thread] Current Thread [Next in Thread]