g | x | w | all
Bytes Lang Time Link
003Japt hx221218T131318ZShaggy
024x86240911T022915Zqwr
012K ngn/k221223T214430Zcoltim
057Red240909T075237ZGalen Iv
040bc240909T062947Zroblogic
025Arturo230106T162010Zchunes
006Husk240908T184542Zint 21h
104Acc!!221220T055726ZDLosc
041JavaScript230125T171920ZEzioMerc
012Uiua 0.11.0240415T032001ZTbw
031sed r240414T222229Zguest430
007Pip221218T203311Zmath sca
nanCommodore BASIC C64/128230725T132934ZShaun Be
001Thunno 2 S230627T183429ZThe Thon
112Racket230725T121124ZEd The &
029Bash +coreutils221223T144909Zroblogic
038Kamilalisp230628T082946ZKamila S
043Lua230409T220931Zbluswimm
110Java 8 OpenJDK 8230402T105913ZFhuvi
008vemf230402T061024Zla.evis.
104jonesforth230402T115307Zallisonl
nan230124T201511ZThe Thon
045Nibbles230124T190818Zxigoi
031Octave221218T180803Z97.100.9
028jq R230106T143005Zpmf
015J221219T211506Zsouth
100Java 19221227T185035ZJeremy
031Ruby221219T013941ZJordan
028Julia221224T120423Zskuss
053Prolog SWI221225T144046ZnaffetS
007Pyt221225T143015ZKip the
166Matlab221223T041932ZFelipe_
051Kotlin221222T213317ZSeggan
045Python 3221220T113854Zuser1139
006Brachylog221219T142700ZFatalize
032Excel221218T174426Zjdt
032Python 2221218T112657ZW D
nanFig221219T181601ZSeggan
013sclin221218T142343ZMama Fun
033Zsh221218T113324Zpxeger
00505AB1E221219T112702ZThe Thon
041Python 3221218T125113ZSectorCo
061Desmos221219T084350ZAiden Ch
002flax221219T081014Zzoomlogo
018BQN221219T052637ZDLosc
025Factor + math.unicode221219T021406Zchunes
018Perl p221219T005740ZnaffetS
035Python 3221218T132536ZNeel Shu
049Haskell221218T214841ZnaffetS
030Julia 1.0221218T214552ZMarcMush
036R221218T144224Zpajonk
005Jelly221218T175237Zcaird co
012pl – Perl OneLiner Magic Wand221218T124350ZDaniel
007Charcoal221218T143206ZNeil
012Retina 0.8.2221218T142752ZNeil
035Python 3221218T135155ZU13-Forw
002Vyxal221218T135022Zmath sca
077Dart 2.18.4221218T131621ZAlex
009Pyth221218T123028ZManish K
014><>221218T121105ZEmigna
030JavaScript ES6221218T113433ZArnauld
035C gcc221218T114759Zl4m2
015Raku221218T113449ZJo King

Japt -hx, 3 bytes

Or 2 bytes with input as a string, or 1 byte with input as a digit array.

ì ó

Try it

ì ó     :Implicit input of integer
ì       :Convert to digit array
  ó     :Uninterleave
        :Implicit output of sum of last element

x86, 24 bytes

Since the question counts the digits left-to-right, this routine pushes digits from right-to-left onto the stack, then accumulates the sum as it pops digits left-to-right. Using the stack is efficient as push/pop are both one byte. Input and output in eax, and all other registers used are clobbered. Input is assumed to be a positive integer less than 2^31 as specified vaguely in the question: "smaller than a 32-bit integer" (as well as test cases).

The code ends up being decently short because div conveniently computes the quotient and remainder in one instruction, and the quotient ends in the accumulator eax, the same register as the (lower half) dividend for the next iteration. The same eax which is zero after all digits are pushed then becomes the sum. The digit counter is naturally ecx, which lets me use the ol' loop to save another byte. Also pleasingly, every instruction ends up being two bytes or less.

sumdig2:                        ; input n in eax
  31 C9     xor     ecx, ecx    ; i = 0
  6A 0A     push    10     
  5F        pop     edi         ; load divisor 10
            
.pushes:
  99        cdq                 ; zero edx, assuming eax sign bit is 0
  F7 F7     div     edi         ; eax = n / 10, edx = n % 10 
  52        push    edx         ; push digit
  41        inc     ecx         ; ++i
  85 C0     test    eax, eax    ; do while (n != 0) 
  75 F7     jnz     .pushes 
                                ; eax sum = 0 
.pops:
  5A        pop     edx         ; pop and discard digit
  49        dec     ecx         ; --i
  74 05     jz      .done       ; break if i == 0
  5A        pop     edx         
  01 D0     add     eax, edx    ; sum += popped digit
  E2 F7     loop    .pops       ; --i; loop if i != 0

.done:
  C3        ret                 ; output in eax

It doesn't seem to be shorter to keep track of digit count parity and conditionally add, rather than "unrolling" and having an extra break condition. Even with my idea to reuse edi, starting at a known positive value, and neg (2 bytes) to flip sign, it's still the same byte count.

.pops:
  5A        pop     edx         ; pop digit
  F7 DF     neg     edi         ; flip sign
  78 02     js     .nosum       
  01 D0     add     eax, edx    ; sum += popped digit
.nosum:
  E2 F7     loop    .pops       ; --i; loop if i != 0

K (ngn/k), 13 12 bytes

+/(=\0&)#10\

Try it online!

Red, 57 bytes

func[n][s: 0 foreach[_ e]form n[s: s - 48 + any[e#"0"]]s]

Try it online!

bc, 40 bytes

for(i=length(a);i>=0;i-=2)b+=a/10^i%10;b

Try it online! 42b

Based on my similar bc solution, but iterating from left to right.

Arturo, 32 29 27 25 bytes

$=>[∑map digits&=>[&&]]

Try it

Husk, 6 bytes

Σ→TC2d

Try it online!

A function that takes in a number and returns the sum of its even digits.

Commented:

        # implicit input
      d # split the number into its digits 12345 -> [1,2,3,4,5]
    C2  # separate into pairs of digits [[1,2],[3,4],[5]]
   T    # transpose into 2 sublists: [[1,3,5],[2,4]]
 →     # drop the first sublist
Σ       # sum up everything

Acc!!, 176 146 104 bytes

-30 bytes thanks to an idea from Mukundan314

Another -42 bytes thanks to several innovative tricks from Mukundan314

Count i while N {
_+N%48%10
}
Count d while 1 {
Count i while 10/(_/10^d+1) {
Write _/10^(d-i)%10+48
}
}

Try it online!

Explanation

# Loop while [read next character] is not 0 (EOF)
Count i while N {
  # Read another character and add the digit it represents to the running tally
  # in the accumulator
  # Map characters 48..57 to values 0..9 and character 10 (newline) to 0
  _+N%48%10
}

# Figure out how many digits the accumulator value has
Count d while 1 {
  # The i loop doesn't run until d is the most significant digit of the accumulator
  # value, at which point it outputs all the digits and then throws an error,
  # ending the program
  # d is the most significant digit when _/10^d is 9 or less
  # Normally, we could make that comparison by checking 9/(_/10^d), but that
  # causes an error if the accumulator is 0, so we instead check whether _/10^d+1
  # is 10 or less
  Count i while 10/(_/10^d+1) {
    # Output each digit from most significant to least significant
    Write _/10^(d-i)%10+48
    # When d-i becomes negative, the expression is a float, and Write throws
    # an error because Python's chr() doesn't accept a float argument
  }
}

JavaScript, 41 bytes

Without recursion:

n=>[...''+n].reduce((s,n,i)=>s+=-i%2&n,0)

Try it:

f=n=>[...''+n].reduce((s,n,i)=>s+=-i%2&n,0)

console.log(f(10))         // 0
console.log(f(101011))     // 1
console.log(f(548915381))  // 26
console.log(f(999999))     // 27
console.log(f(2147483647)) // 29
console.log(f(999999999))  // 36

UPD 42 -> 41

Thanks to l4m2 for the tip to reduce bytes count

Uiua 0.11.0, 12 bytes SBCS

/+≡⋕▽◿2⇡⧻.°⋕

Try on Uiua Pad!

Takes \$n\$ and returns the sum of every other digit of \$n\$.

Explanation

°⋕ # stringify n
⧻. # length of string
⇡  # range [0 ... length]
◿2 # modulo 2, [0 1 0 1 ...]
▽  # filter string by that
≡⋕ # parse each digit
/+ # sum of digits

sed -r, 31 bytes

s/.(.)?/\1+/g
s/.*/bc<<<$[&0]/e

Try it online!

or equivalantly,

sed -r, 31 bytes

s/.(.)?/\1+/g
s/.*/echo $[&0]/e

Try it online!

Pip, 10 7 bytes

$+@SUWa

First pip answer, so don't sue me plz.

Try It Online!

Explanation

$+@SUWa
  @SUWa  Uninterweave a, take the second item of the two "every second element" lists 
$+       Sum the string

Commodore BASIC (C64/128, C16/+4, VIC-20, PET, THEC64 Mini/THEC64/THEVIC20) - 88 BASIC Bytes

0 inputn$:iflen(n$)=0thenend
1 iflen(n$)<2orval(n$)<9then3
2 fori=2tolen(n$)step2:n=n+val(mid$(n$,i,1)):next
3 printn

A quick explanation

Sum every second digit in a number, Commodore C64

Thunno 2 S, 1 byte

^

Try it online!

Thunno 2, 2 bytes

^S

Try it online!

Explanation

^S  # Implicit input  ->  548915381
^   # Uninterleave    ->  [5,8,1,3,1], [4,9,5,8]
 S  # Sum the list    ->  [5,8,1,3,1], 26
    # Implicit output

Racket, 112 bytes

((λ(l)(for/sum([i(range(length l))]#:when(odd? i))(-(char->integer(list-ref l i))48)))(string->list(~a(read))))

Try it online!


Explanation

Creates an anonymous function that receives user input as a list of characters. It then iterates through the length of the list. If the index is an odd number, we transform the current charater into a digit and add it to the sum.

((lambda (lst)
   (for/sum ([index (range (length lst))]
             #:when (odd? index))
     (- (char->integer (list-ref lst index)) 48)))
 (string->list (~a (read))))

The mysterious "89" with no input

If you supply this program with no input, you will notice that the final sum would be 89.

That is because we convert the result of read directly into a string.

(~a (read))

When there is no input, the read function returns #<eof>. Our code converts the #<eof> symbol to a string, "#<eof>". Then it loops through all the characters that have odd indices, giving us a list of '(#\< #\o #\>). After that, the characters are converted into ASCII numbers. Since the ASCII value of "0" is 48, we subtract 48 from the result:

; (x - 48 becomes y)
'((#\<  12)
  (#\o  63)
  (#\>  14))

The numbers are then summed together to get 89.


Have a wonderful week ahead!

Bash +coreutils, 29 bytes

fold -2|cut -c2|paste -sd+|bc

Try it online!


Alternatives (38b, 46b)

echo `sed -E s'/(.)([0-9])/\2+/g'`0|bc
for z in `fold -1`;{((t+=i++%2?z:0));};echo $t

Kamilalisp, 38 bytes (APL SBCS)

λ x \⌿⊙← + \⍠¨ *&[$(^mod 2)#0]\⌹⊙ 10 x

Attempt This Online!

Lua, 43 bytes

a=0(...):gsub('.(.)',load'a=...+a')print(a)

Try it online!

Java 8 (OpenJDK 8), 110 112 bytes

-2 bytes thanks to @ceilingcat !

Solution using only a single inline Stream, and using a 2-cell array as the accumulator of the reduce to carry both the sum and the index of the current cell.

This could easily be outgolfed by a more classic Java solution.

n->(n+"").chars().mapToObj(e->new int[]{e-48}).reduce(new int[2],(a,b)->new int[]{a[0]+a[1]%2*b[0],++a[1]})[0]

Try it online!

vemf, 25 8 bytes

-17 bytes thanks to language creator

Well this is a fun one.

ª‼│%2╕º+

try it online - uses 8472 as an example

Explanation

ª‼│%2╕º+

ª        ' convert to string
 ‼       ' repeat each character...
  │%2    ' (index mod 2) times
     ╕º  ' convert them back to numbers
       + ' sum

Old answer (25 bytes):

{`l←╢αª♣ó╕=_1·αª╕‼.l,-:48+

try it online

Explanation

{`l←╢αª♣ó╕=_1·αª╕‼.l,-:48+

{                          ' define function. (closing } optional)

 `l←                       ' make a list:
    ╢                      ' (group next 9 characters)
         ╕                 ' for each element of
       ♣                   ' the domain of
     αª                    ' left argument as string,
        ó                  ' is (-1)^x
          =_1              ' equal to -1?
             ·             ' discard the return value

              স          ' for each character,
                 ‼         ' repeat it
                  .l       ' by the corresponding list entry
                    ,      ' concatenate the resulting list
                     -:48  ' subtract 0x30 from each entry, so 1 maps to 0x01 etc
                         + ' sum

jonesforth, 104 bytes

: F DUP UWIDTH 1 AND IF BASE @ / THEN 0 SWAP BEGIN BASE @ /MOD -ROT + SWAP BASE @ / DUP NOT UNTIL DROP ;

Less obfuscated version:

: F
    \ make sure we have an even number of digits
    DUP UWIDTH
    1 AND
    IF BASE @ / THEN

    0 SWAP
    ( accumulator value )
    BEGIN
        \ add the smallest digit to the accumulator
        BASE @ /MOD ( acc rem quot )
        -ROT + SWAP
        \ discard the new smallest digit
        BASE @ / ( acc v )
        \ loop until the value is 0
        DUP NOT
    UNTIL
    DROP
;

This answer needs UWIDTH, which gforth doesn't have, so I specified jonesforth because it definitely works on jonesforth.

It compiles to 124 bytes, which drops to 116 if you have constants defined for 0 and 1. On a 16 bit forth it would theoretically be half that. Also it has the added bonus of working in any base between 2 and 36.

Thunno, \$ 6 \log_{256}(96) \approx \$ 4.94 bytes

dZlAKS

Attempt This Online!

Explanation:

dZlAKS  # Implicit input
d       # Cast to digits
 Zl     # Uninterleave
   AK   # Get last element
     S  # Sum this list
        # Implicit output      

Nibbles, 4.5 bytes

+`%~>>`@~

Attempt This Online!

Explanation

+   Sum of
`%~  select every second element, starting at first, in
>>    remove first element of
`@~    base 10 digits of
        input

Octave, 31 bytes

@(s)sum(num2str(s)(2:2:end)-48)

Try it online!

This converts the number to a string, sums up the character codes in the string, then subtracts the ASCII code for 0 (48) from each character.

jq -R, 28 bytes

[scan("..")|tonumber%10]|add

Try it online!

J, 15 bytes

All credit goes to Raul.

[:+/_2}.\,.&.":

Attempt This Online!

[:+/_2}.\,.&.":
         ,.&.":  NB. equivalent to ". ,. ": y, convert to digit list
    _2}.\        NB. behead each non-overlapping window of size 2
[:+/             NB. sum the resulting column

My original 19 bytes from 11 bytes

1(#.]*0 1$~#),.&.":

Updated to reflect challenge requirements. Thanks to Jonah for the modifications.

Attempt This Online!

1(#.]*0 1$~#),.&.":
             ,.&.":  NB. same as above
1(          )        NB. dyadic hook
           #         NB. use length of right arg to
      0 1$~          NB. reshape 0 1, reuses elements to create alternating 1's
    ]*               NB. multiply by the right arg
  #.                 NB. 1 #. y sums the result 

Java 19, 100 bytes

Partial program assuming n is the given number:

var m=0;var s=String.valueOf(n);for(var i=1;i<s.length();i+=2)m+=s.charAt(i)-48;System.out.print(m);

Full program using standard input:

interface A{
    static void main(String[]a){
        var n=Integer.parseInt(a[0]);
        //
        var m=0;
        var s=String.valueOf(n);
        for(var i=1;i<s.length();i+=2)m+=s.charAt(i)-48;
        System.out.print(m);
        //
    }
}

Ruby, 40 32 31 bytes

-8 bytes thanks to G B
-1 byte thanks to Armand Fardeau

->n{eval"#{n}".scan(/.(.)/)*?+}

Attempt This Online!

Julia, 28 bytes

f(n)=sum(digits(n)[2:2:end])

Prolog (SWI), 53 bytes

\X:-get(_),get(C),C>0,Z is X+C-48,\Z;write(X).
:- \0.

Try it online!

Full program.

Pyt, 7 bytes

ąĐƩ⇹ƧƩ-

Try it online!

ąĐƩ⇹ƧƩ-
ą         implicit input (n); convert n to array of digits
 Đ        duplicate top of stack
  Ʃ       sum the digits of n
    ⇹     swap the top two items on the stack
     ƧƩ   sum every other digit of n, starting with the first
      -   subtract; implicit print

Matlab, 166 bytes

n = input('Input : ', 's');
d = str2double(regexp(n,'\d','match')); %convert n to a unidimensional matrix 
total = 0; %stores total sum
    for i = 2:2:length(d) %traverse the unidimensional matrix [ vector ]
        total = total + d(i); %sum of every second n
    end
disp(['Output : ', num2str(total)]);

enter image description here

Kotlin, 51 bytes

{it.map{it.code-48}.foldIndexed(0){i,a,c->i%2*c+a}}

No TIO link as it doesn't have an updated version, ATO borks with it for some reason.

{it.map{it.code-48}.foldIndexed(0){i,a,c->i%2*c+a}} // String input
{                                                 } // Lambda expression
 it.map{it.code-48}                                 // Subtract 48 from each char, turning the string into a list of digits
                   .foldIndexed(0){i,a,c->       }  // Fold over the list, starting with 0. i is the index, a is accumulator, and c is the digit
                                          i%2*c     // Multiply the current digit by the index mod 2. If it is even, it resolves to 1*c, otherwise 0*c
                                               +a   // Add to accumulator

Python 3, 45 bytes

e=lambda n:sum([int(x)for x in str(n)[1::2]])

Try it online!

Brachylog, 8 6 bytes

ġ₂z₁t+

Try it online!

-2 bytes thanks to @DLosc.

Explanation

ġ₂         Group consecutive digits into sublists of 2 elements
  z₁       Zip
     t     Tail
       +   Sum

Excel, 39 32 bytes

=SUM(--(0&MID(A1,2*ROW(A:A),1)))

enter image description here

Python 2, 39 32 bytes

-7 (pxeger suggested lambda)

lambda n:sum(map(int,`n`[1::2]))

TIO

EDIT: new test cases

Fig, \$3\log_{256}(96)\approx\$ 2.469 bytes

S]y

Try it online!

Port of Vyxal.

S]y
    # Uninterleave
 ]  # Get last
S   # Sum

Fig, \$6\log_{256}(96)\approx\$ 4.939 bytes

S-n2'0

Try it online!

My original answer before seeing Vyxal.

S-n2'0 # Input as a digit list
  n    # For every
   2   # Second item
    '  # Replace
     0 # With a 0
 -     # Subtract this from the original list
S      # Sum

sclin, 13 bytes

2/`1.: map +/

Try it here!

For testing purposes:

"548915381" ; n>o
2/`1.: map +/

Explanation

Prettified code:

2/` 1.: map +/

Zsh, 33 bytes

for _ c (`fold -1`)let t+=c;<<<$t

Attempt This Online!

-3 bytes thanks to roblogic

Inputs as a string, because there is no way to input as a number in Zsh.

05AB1E, 5 bytes

2ι`SO

Try it online!

Explanation

2ι`SO  # Implicit input                          TOP OF STACK:
2ι     # Get every second character              ["58131", "4958"]
  `    # Dump onto the stack                     "4958"
   S   # Cast to a list of characters            ["4", "9", "5", "8"]
    O  # Sum it up (implicit cast to integer)    26

Python 3, 41 bytes

lambda n:sum(int(i)for i in str(n)[1::2])

Try it online!

Desmos, 61 bytes

D=floor(logk)
f(k)=∑_{n=0}^Dmod(n+D,2)mod(floor(k/10^n),10)

Try It On Desmos!

Try It On Desmos! - Prettified

There must be some better way to do this other than separating out the D=floor(logk) lol.

flax, 2 bytes

ΣẎ

Try It Online!

BQN, 18 bytes

1⊑·+˝⌊‿2⥊'0'-˜•Fmt

Anonymous tacit function that takes a number and returns a number. Try it at BQN online!

Explanation

1⊑·+˝⌊‿2⥊'0'-˜•Fmt
               •Fmt  Format as string
          '0'-˜      Subtract '0' character from each, giving a list of digits as numbers
     ⌊‿2⥊           Reshape into an array with two columns, dropping the last digit if
                     there is an odd number of digits
  ·+˝                Sum down each column
1⊑                   Take the element at index 1 (0-indexed) in the resulting list

Factor + math.unicode, 25 bytes

[ >dec <odds> 48 v-n Σ ]

Try it online!

       ! 548915381
>dec   ! "548915381"
<odds> ! "4958"
48     ! "4958" 48
v-n    ! { 4 9 5 8 }
Σ      ! 26

Perl -p, 18 bytes

s/.(.)/$\+=$1/ge}{

Try it online!

Input via STDIN.

Python 3, 28 37 32 30 35 bytes

lambda n:sum(map(int,str(n)[1::2]))

Assuming input is a string number

Haskell, 49 bytes

f s=sum[read[x]|(i,x)<-zip[0..]$show s,mod i 2>0]

Try it online!

Julia 1.0, 30 bytes

!n=sum(i->i-'0',"$n"[2:2:end])

Try it online!

R, 40 38 36 bytes

Edit: -2 bytes thanks to @Giuseppe.

\(x)sum(x%/%10^(nchar(x):0)%%10*1:0)

Attempt This Online!

Jelly, 5 bytes

D0ÐoS

Try it online!

Also 5 bytes

DŻm2S

Try it online!

Also also 5 bytes

Ds2SṪ

Try it online!

How they work

D0ÐoS - Main link. Takes an integer on the left
D     - Digits
  Ðo  - To digits in odd positions:
 0    -   Set them to 0
    S - Sum

DŻm2S - Main link. Takes an integer on the left
D     - Digits
 Ż    - Prepend a zero
  m2  - Take every second element
    S - Sum

Ds2SṪ - Main link. Takes an integer on the left
D     - Digits
 s2   - Slice into pairs
   S  - Sums
    Ṫ - Tail

pl – Perl One-Liner Magic Wand, 12 bytes

Use -o to loop over command line arguments. Global matching regexp returns every other character, in this case digit. By default List::Util::sum is imported, e(cho) its result. On the blog, hover the ▶ button, or the blue code box, to see the result:

pl -o 'e sum/.(.)/g' 10 101011 548915381 999999 2147483647 999999999

Charcoal, 7 bytes

IΣΦS﹪κ²

Try it online! Link is to verbose version of code. Explanation:

   S    Cast the input to string
  Φ     Filter characters where
     κ  Current index
    ﹪ ² Is odd
 Σ      Take the sum
I       Cast to string
        Implicitly print

Retina 0.8.2, 12 bytes

.(.?)
$1$*
.

Try it online! Link includes test cases. Takes input as a string because Retina has no integer types. Explanation:

.(.?)
$1$*

Convert alternate digits to unary, dropping the other digits.

.

Take the sum and convert back to decimal.

Python 3, 35 bytes

lambda n:sum(map(int,f'{n}'[1::2]))

Try it online!

Vyxal, 2 bytes

y∑

well.

Try it Online! | 1 byte with s

Explanation

y∑
y   Uninterleave, push two lists with every second and every second+1 digit
 ∑  Sum the first list

Dart (2.18.4), 92 77 bytes

f(n,[i=1])=>[for(;i<(n='$n').length;i+=2)int.parse(n[i])].reduce((v,e)=>v+e);

Pyth, 9 bytes

tssM%2+1z

Try it online!

      +1z    # Append '1' before the input
    %2       # Every 2nd element of
 ssM         # Map to integer and take sum
t            # Decrease by 1

><>, 14 bytes

0i~i:c%@0(?n+!

Try it online!

Explanation

0               # init sum as 0
 i~             # discard an input
   i:           # duplicate an input
     c%@        # mod the copy by 12 and move down on stack
        0(?n    # if the other copy was negative, print the sum
            +!  # else add copy to sum and skip the next instruction

JavaScript (ES6), 30 bytes

-1 by @l4m2

f=n=>n&&f(i=n/10|0)+i++%2*n%10

Try it online!


JavaScript (ES6), 31 bytes

f=n=>n?f(n/10|0)+i++%2*n%10:i=0

Try it online!

Commented

f = n =>            // f is a recursive function taking the input n
  n ?               // if n is not equal to 0:
    f(n / 10 | 0) + //   do a recursive call with floor(n / 10)
                    //   it's important to understand that:
                    //     1) n is defined in the local scope of f
                    //     2) i is defined in the global scope
                    //     3) we're not going to execute the code that
                    //        follows until the recursion stops and i
                    //        has been initialized
    i++ % 2 *       //   take the parity of i (increment it afterwards)
    n % 10          //   and multiply by the least significant decimal
                    //   digit of n
  :                 // else:
    i = 0           //   stop the recursion and initialize i to 0

C (gcc), 35 bytes

i;f(n){n=n?f(i=n/10)+i++%2*n%10:0;}

Try it online!

Port of js solution

Raku, 15 bytes

{sum m:g/.<(./}

Try it online!

Simple regex based sum of every other digit