g | x | w | all
Bytes Lang Time Link
052Swift 6250515T124248ZmacOSist
028Perl 5 MListUtil=sum pF240417T162431ZXcali
005Vyxal 3250514T163210ZThemooni
nanStandard Pascal250514T161624ZJOrE
031Juby221201T165329ZJordan
024CASIO BASIC CASIO fx9750GIII250425T190931Zmadeforl
046Tcl170801T234755Zsergiol
036JavaScript ES6170710T164955ZArnauld
009Pip221202T000924ZnaffetS
012K ngn/k221201T163052Zcoltim
017Uiua240126T184029ZJoao-3
003Vyxal 3240126T161351Zpacman25
018x8616 machine code230623T200812Z640KB
006Thunno 2230623T172629ZThe Thon
nan230302T085110ZThe Thon
026Arturo230302T031618Zchunes
nanFig221201T162856ZSeggan
008Japt221201T161654ZShaggy
006MathGolf221201T141525ZKevin Cr
612Nibbles221201T110316ZDominic
024Desmos221201T080141ZAiden Ch
024Ly221201T075208Zcnamejj
006Vyxal221201T030206ZnaffetS
008Pyth170711T072057ZMr. Xcod
026APL NARS171217T141821Zuser5898
011J171216T172514ZFrownyFr
073Rust171216T153735ZProgramF
045Ruby171216T144834ZUnihedro
035AWK171216T143941ZUnihedro
051Bash171216T143513ZUnihedro
009TIBasic170710T181812ZTimtech
014J170710T173056ZJonah
006TIBASIC170711T005824Zlirtosia
064Java OpenJDK 8170711T123713Ztfantons
314java170712T110527Zjahly
030x8664 Machine Code170712T103612ZCody Gra
052Common Lisp170711T080249ZRenzo
020Mathematica170710T202231ZZaMoC
014CJam170712T062922Zgeokavel
nanSHENZHEN I/O MCxxxx scripts170710T173822ZCalculat
nan170710T230658ZMark
057C#170711T214807ZTyCobb
00705AB1E170711T204828ZMagic Oc
029R170710T211459Zrunr
067C#170711T101740ZTheLetha
059C#170711T121720ZElectric
039Python 2170710T165117ZDead Pos
055Java OpenJDK 8170711T100740ZOlivier
032><>170711T092856ZSok
099Bash 99 Bytes170710T183235ZADDB
025Haskell170710T173514Zbartavel
054PHP170710T171611ZJör
043R170710T184827ZRudier
018Braingolf170710T193757ZMayube
067Mathematica170710T191010ZZaMoC
008APL170710T170438ZUriel
051PHP170710T174534ZTitus
057C gcc170710T165514Zcleblanc
00605AB1E170710T174407ZDatboi
006Jelly170710T164243ZDennis
007Husk170710T170839ZLeo
028Perl 6170710T173059ZSean
007Neim170710T171521ZOkx
019Julia 0.5170710T170451ZDennis
008Japt170710T170414ZETHprodu

Swift 6, 52 bytes

let s={abs(($0+[]).map{$0%2>0 ?$0:-$0}.reduce(0,+))}

Try it on SwiftFiddle!

Perl 5 -MList::Util=sum -pF, 28 bytes

$_=abs sum map$_*(-1)**$_,@F

Try it online!

Perl 5 -pF, 32 bytes

map$;+='-'x($_%2).$_,@F}{$\=abs$

Try it online!

Vyxal 3, 5 bytes

⑧?*•⦷

Vyxal It Online!

Vyxal 3 port of many existing answers:

abs(input • map(n=>{-1^n}, input))

Since it was too boring, I also came up with

Vyxal 3, 10 bytes

ƛk+nei×}∑⦷

Vyxal It Online!

ƛk+nei×}∑⦷­⁡​‎⁠⁠‎⁡⁠⁣⁢‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁣⁡‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢⁤‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁢‏⁠‎⁡⁠⁣‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏‏​⁡⁠⁡‌⁢⁢​‎‎⁡⁠⁢⁣‏‏​⁡⁠⁡‌­
         ⦷  # ‎⁡abs(
        ∑   # ‎⁢    sum(
ƛ      }    # ‎⁣        map(n=>...,input)
 k+         # ‎⁤[-1,1]
   nei      # ‎⁢⁡      [n%2==0]
      ×     # ‎⁢⁢              *n
💎

Created with the help of Luminespire.

<script type="vyxal3">
⑧?*•⦷,
ƛk+nei×}∑⦷,
</script>
<script>
    args=[["[0]"],["[1]"],["[1,2]"],["[3,3,3]"],["[4,5,9]"],["[2,4,6,9]"],["[1,2,3,4]"]]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>

Standard Pascal, 197/174 bytes

If function input was a number (197 bytes):

function D(n:int64):int64;var x,q,r:integer;s:string;begin S:=IntToStr(n);For X:=1 to length(S) do if (StrToInt(S[x]) mod 2)=0 then Q:=Q+Strtoint(S[x]) else R:=R+Strtoint(s[x]);Result:=Abs(Q-R)end;

If the function input was the number but in string, may be cheating (174 bytes):

function D(s:string):int64;var x,q,r:integer;begin for X:=1 to length(S) do if (StrToInt(S[x]) mod 2)=0 then Q:=Q+Strtoint(S[x]) else R:=R+Strtoint(s[x]);Result:=Abs(Q-R)end;

J-uby, 31 bytes

:partition+:odd?|:*&:sum|+:-|:|

Attempt This Online!

CASIO BASIC (CASIO fx-9750GIII), 24 bytes

?→List1
List1 Rmdr 2
Abs Sum (List1Not Ans-List1Ans

Tcl, 46 bytes

puts [expr abs([lmap e $V {list +$e*-1**$e}])]

Try it online!

JavaScript (ES6),  43 38  36 bytes

-2 thanks to @l4m2

Takes input as an array of digits.

a=>!a.map(d=>s+=d&1?d:-d,s=0)>s?-s:s

Try it online!

Pip, 9 bytes

AB$+g*vEg

Try It Online!

K (ngn/k), 18 15 12 bytes

#!+/{x-:/x}'

Try it online!

Takes input as a list of digits.

Uiua, 17 bytes

⌵-∩/+∩▽¬,,◿2.∵⋕°⋕

Test pad

Explanation

⌵-∩/+∩▽¬,,◿2.∵⋕°⋕­⁡​‎‎⁡⁠⁤⁢‏⁠‎⁡⁠⁤⁣‏⁠‎⁡⁠⁤⁤‏⁠‎⁡⁠⁢⁡⁡‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁣⁣‏⁠‎⁡⁠⁣⁤‏⁠‎⁡⁠⁤⁡‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁣⁡‏⁠‎⁡⁠⁣⁢‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁢⁤‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏‏​⁡⁠⁡‌⁢⁢​‎‎⁡⁠⁣‏⁠‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏‏​⁡⁠⁡‌⁢⁣​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏‏​⁡⁠⁡‌­
             ∵⋕°⋕  # ‎⁡Parse integer into digits
          ◿2.      # ‎⁢Get each digit mod 2
        ,,         # ‎⁣Copy the digits and the mask over
       ¬           # ‎⁤Invert the mask
     ∩▽            # ‎⁢⁡Filter for both masks and arrays
  ∩/+              # ‎⁢⁢Sum both results up
⌵-                 # ‎⁢⁣Get the absolute difference
💎

Created with the help of Luminespire.

Vyxal 3, 3 bytes

ṂḋȦ

Try it Online!

Port of Dennis's Jelly answer.

Certified Vyxal Moment, -1^n and dot product are now one byte builtins.

Input is a list of digits

x86-16 machine code, 18 bytes

00000000: 33d2 ada8 0174 02f7 d803 d0e2 f579 02f7  3....t.......y..
00000010: dac3                                     ..

Listing

33 D2       XOR  DX, DX         ; result in DX 
        IN_LOOP: 
AD          LODSW               ; next digit 
A8 01       TEST AL, 1          ; odd or even? 
74 02       JZ   EVEN           ; jump if even 
F7 D8       NEG  AX             ; complement to subtract odd digit 
        EVEN: 
03 D0       ADD  DX, AX         ; add to running result 
E2 F5       LOOP IN_LOOP        ; next digit 
79 02       JNS  DONE           ; jump if result is positive 
F7 DA       NEG  DX             ; complement for absolute value
        DONE: 
C3          RET                 ; return to caller

Callable function, input list of digits at DS:SI, length in CX. Output to DX.

Thunno 2, 6 bytes

u@$Ø.A

Attempt This Online!

Port of Dennis's Jelly answer.

Explanation

u@$Ø.A  # Implicit input
u@      # Take -1 to the power of
        # each of the digits
  $     # Push the input again
   Ø.   # Take the dot product
     A  # Absolute value
        # Implicit output

Thunno, \$ 9 \log_{245}(96) \approx \$ 7.41 bytes

D1n@z*SZA

Attempt This Online! or verify all test cases.

Explanation

D1n@z*SZA  # Implicit input        [1, 2, 3, 4]
D          # Duplicate             [1, 2, 3, 4], [1, 2, 3, 4]
 1n@       # Push -1 ** each       [1, 2, 3, 4], [-1, 1, -1, 1]
    z*     # Multiply elementwise  [-1, 2, -3, 4]
      S    # Sum this list         2
       ZA  # Absolute value        2
           # Implicit output

Arturo, 26 bytes

$=>[abs∑map&'x->x*^0-1x]

Try it

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

AS*^N1

Try it online!

Port of MathGolf. Surprisingly, beats Jelly.

AS*^N1 # Input as list of digits
    N1 # -1
   ^   # To the power of each in the input
  *    # Multiply the list of 1s and -1s by each digit
 S     # Sum
A      # Absolute value

Japt, 8 bytes

üv mx ra

Try it

Takes input as a digit array

üv mx ra     :Implicit input of digit array
ü            :Group by
 v           :  Divisible by 2?
   m         :Map
    x        :  Sum
      r      :Reduce by
       a     :  Absolute difference

MathGolf, 6 bytes

b▬m*Σ±

Port of @Dennis' Jelly answer.

Input as a list of digits.

Try it online.

Explanation:

b      # Push -1
 ▬     # Take -1 to the power of each integer in the (implicit) input-list
  m*   # Multiply the values at the same positions of this list and the (implicit) input
    Σ  # Sum this list together
     ± # Get its absolute value
       # (after which the entire stack is output implicitly as result)

Nibbles, 6 bytes (12 nibbles)

!=+$*+|$%$~~

Calculates the absolute difference between the sum of all digits and twice the sum of the odd digits.

!=+$*+|$%$~~
!=              # absolute difference between
  +             #   sum of 
   $            #   input
                # and
     +          #   sum of 
       $        #   input 
      |         #   filtered for nonzero when
        %$      #     modulo
          ~     #     2 (default for modulo)
    *           #   multiplied by
           ~    #   2 (default for multiplication)  

enter image description here

Desmos, 24 bytes

f(l)=abs(total(l(-1)^l))

Input as a list of digits.

Try It On Desmos!

Try It On Desmos! - Prettified

Ly, 24 bytes

0spSy[f:2%2*,*l+sp,]lar-

Try it online!

This is pretty brute force, it just adds or subtracts each number to an accumulator depending on whether it's odd or even. The post-loop bit is the shortest way to get an abs() in Ly I could think of.

0sp                       - initialize the backup cell to 0, clear stack
   S                      - convert the number on STDIN to digits on the stack
    y                     - push the number of digits onto the stack
     [f           ,]      - loop decrementing the digit count, stop on 0
       :                  - duplicate the next digit
        2%                - modulo by 2 to get odd/even
          2*,             - do "(x*2)-1" to map 1 to 1, and 0 to -1
             *            - multiple the digit by that 1/-1
              l+sp        - add to backup cell, pop from stack
                    l     - load the final difference from accumulator
                     a    - sort stack (has a 0 and the accumulator val)
                      r   - reverse stack
                       -  - subtract to flip the sign if difference was <0

The programs with a positive number on the stack, which is printed automatically.

Vyxal, 6 bytes

u$eÞ•ȧ

Try it Online!

Port of Jelly.

u$eÞ•ȧ
u$e     # Raise -1 to the power of each
   Þ•   # Dot product with the input
     ȧ  # Absolute value

Pyth, 16 12 11 10 8 bytes

.asm*^tZ

Try it online!


How?

.asm*^tZ – Full program. Q = input.
   m*^tZ – Raise -1 to the power of each d in Q and multiply by d.
  s      – Sum.
.a       – Absolute value.

APL NARS 26 chars

{∣(+/-a)+2×+/(2∣a)/a←⍎¨⍕⍵}

test

  f←{∣(+/-a)+2×+/(2∣a)/a←⍎¨⍕⍵}
  f¨0 1 12 333 459 2469 1234
0 1 1 9 10 3 2

J, 11 bytes

Credit to Uriel’s APL solution

1|@#.[*_1^]

Try it online!

Rust, 73 bytes

fn f(mut a:i32)->i32{let mut s=0;while a>0{s+=a%10*(a%2*2-1);a/=10}s.abs()}

Try it online!

Rust, 68 bytes

This takes a slice of digits rather than an integer.

fn z(a:&[i32])->i32{a.iter().map(|x|x*(x%2*2-1)).sum::<i32>().abs()}

Try it online!

Ruby, 45 bytes

Function; Full number

->n{s=0
n.digits.map{|x|s+=x%2>0?x:-x}
s.abs}

Try it online!

Ruby, 38 bytes

Function; List of digits

->n{s=0
n.map{|x|s+=x%2>0?x:-x}
s.abs}

Try it online!

AWK, 35 bytes

Full program; List of digits

{a+=$0%2?$0:-$0}END{print a<0?-a:a}

Try it online!

Technically not the same as my other answer. I still think that one is better because using a list of digits feels cheap.

Bash, 51 bytes

Full program; Full number

Or "bash with awk" for the pedantics.

grep -o .|awk '{a+=$0%2?$0:-$0}END{print a<0?-a:a}'

Try it online!

Explanation

grep -o .| # every /./ on a new line
awk '{
            // a is initialized to 0 cuz awk lol
  a+=$0%2   // Is odd?
    ?$0:-$0 // true -> add +, false -> add -
}
END{
  print a<0?-a:a // to absolute value
}'

TI-Basic, 18 9 bytes

abs(sum((-1)^AnsAns

Explanation

Multiplies each digit in the list by -1 to its power, negating each odd digit, before summing them.

J, 14 bytes

|-/(2&|+//.[),

Try it online!

explanation

|                absolute value of
 -/              the difference between
                 the items on the list returned by this fork
   (2&|          is an item odd? (1 for yes, 0 for no)
       +//.      the "key" verb /. which partitions on above (even / odd) then sums
           [)    identity, ie, the list of digits passed
             ,   turn it into a list (to handle 1 element case)

TI-BASIC, 11 6 bytes

abs(sum(Anscos(πAns

Takes input as a list. i²^Ans saves two bytes over (-1)^Ans because we don't need the parentheses.

abs(sum(Anscos(πAns
           cos(πAns                  1 for evens, -1 for odds
        Ans                          Multiply by original list
abs(sum(                             Sum the list and take absolute value, which also
                                     fixes rounding errors from cos(.

Java (OpenJDK 8), 64 bytes

Takes n as int input, uses mod 10 and div 10 to sum from least significant digit and return Absolute value when done.

n->{int r=0;for(;n>0;n/=10)r+=n%2>0?-n%10:n%10;return r<0?-r:r;}

Try it online

java , 314 bytes

public  static int f (String s)
{
    char [] m =s.toCharArray();
    int o=0 ,e=0; 
    for(int i =0 ;i<m.length;i++)
    { int n=(int)m[i]-48;
    if(n%2==0)
        e+=n;
    else 
        o+=n;
    }
    return abs(e-o);


   }

x86-64 Machine Code, 30 bytes

31 C0 99 8B 4C B7 FC F6 C1 01 74 04 01 CA EB 02 01 C8 FF CE 75 ED 29 D0 99 31 D0 29 D0 C3

The above code defines a function that accepts a list/array of integer digits and returns the absolute difference between the sum of its even digits and the sum of its odd digits.

As in C, assembly language doesn't implement lists or arrays as first-class types, but rather represents them as a combination of a pointer and a length. Therefore, I have arranged for this function to accept two parameters: the first is a pointer to the beginning of the list of digits, and the second is an integer specifying the total length of the list (total number of digits, one-indexed).

The function conforms to the System V AMD64 calling convention, which is standard on Gnu/UNIX systems. In particular, the first parameter (pointer to the beginning of the list) is passed in RDI (as this is 64-bit code, it is a 64-bit pointer), and the second parameter (length of the list) is passed in ESI (this is only a 32-bit value, because that's more than enough digits to play with, and naturally it is assumed to be non-zero). The result is returned in the EAX register.

If it's any clearer, this would be the C prototype (and you can use this to call the function from C):

int OddsAndEvens(int *ptrDigits, int length);

Ungolfed assembly mnemonics:

; parameter 1 (RDI) == pointer to list of integer digits
; parameter 2 (ESI) == number of integer digits in list (assumes non-zero, of course)
OddsAndEvens:
   xor  eax, eax              ; EAX = 0 (accumulator for evens)
   cdq                        ; EDX = 0 (accumulator for odds)
.IterateDigits:
   mov  ecx, [rdi+rsi*4-4]    ; load next digit from list
   test cl, 1                 ; test last bit to see if even or odd
   jz   .IsEven               ; jump if last bit == 0 (even)
.IsOdd:                       ; fall through if last bit != 0 (odd)
   add  edx, ecx              ; add value to odds accumulator
   jmp  .Continue             ; keep looping
.IsEven:
   add  eax, ecx              ; add value to evens accumulator
.Continue:                    ; fall through
   dec  esi                   ; decrement count of digits in list
   jnz  .IterateDigits        ; keep looping as long as there are digits left

   sub  eax, edx              ; subtract odds accumulator from evens accumulator

   ; abs
   cdq                        ; sign-extend EAX into EDX
   xor  eax, edx              ; XOR sign bit in with the number
   sub  eax, edx              ; subtract sign bit

   ret                        ; return with final result in EAX

Here's a brief walk-through of the code:

__
* The code can be re-written to use simpler addressing modes, but it doesn't make it any shorter. I was able to come up with an alternative implementation that dereferenced RDI and incremented it by 8 each time through the loop, but because you still have to decrement the counter in ESI, this turned out to be the same 30 bytes. What had initially given me hope is that add eax, DWORD PTR [rdi] is only 2 bytes, the same as adding two enregistered values. Here is that implementation, if only to save anyone attempting to outgolf me some effort :-)

                    OddsAndEvens_Alt:
31 C0                   xor    eax, eax
99                      cdq
                    .IterateDigits:
F6 07 01                test   BYTE PTR [rdi], 1
74 04                   je     .IsEven
                    .IsOdd:
03 17                   add    edx, DWORD PTR [rdi]
EB 02                   jmp    .Continue
                    .IsEven:
03 07                   add    eax, DWORD PTR [rdi]
                    .Continue:
48 83 C7 08             add    rdi, 8
FF CE                   dec    esi
75 ED                   jne    .IterateDigits
29 D0                   sub    eax, edx
99                      cdq
31 D0                   xor    eax, edx
29 D0                   sub    eax, edx
C3                      ret

Common Lisp, 52 bytes

(defun f(x)(abs(loop as i in x sum(*(expt -1 i)i))))

Try it online!

Translation of Dead Possum answer.

Mathematica, 20 bytes

Abs@Tr[(-1)^(g=#)g]&

takes as input a list of digits

special thanx to @LLlAMnYP for letting me know about the "new rules"

CJam, 16 14 Bytes

q{si_W\#*}%:+z

Try it online

q{si_W\#     e# Take -1 to power of digit
*}%          e# Multiply result by digit 
:+z          e# Sum altered digits and return the absolute value

SHENZHEN I/O MCxxxx scripts, 197 (126+71) bytes

Chip 1 (MC6000):

mov 0 dat
j:
mov x0 acc
mov 70 x3
mov -1 x3
mov acc x3
mul x3
mov acc x2
mov dat acc
add 1
tlt acc 3
mov acc dat
+jmp j
slx x0

Chip 2 (MC4000):

mov x1 acc
add x1
add x1
mov 30 x0
mov 0 x0
mov acc x0
mov x0 p0
slx x1

EDIT: A more golf-centered approach:

EXCEL, 42 36 29 bytes

Saved 6 bytes thanks to Magic Octopus Urn Saved 7 bytes by using Dennis' -1^ approach (which, I just learned, works on arrays in excel)

=ABS(SUMPRODUCT(A:A,-1^A:A))

Takes a list of integers in A column for input. Probably can be golfed further, or by using the string version, taking a string in A1 for input.

EXCEL, 256 bytes

=ABS(LEN(SUBSTITUTE(A1,1,""))-2*LEN(SUBSTITUTE(A1,2,""))+3*LEN(SUBSTITUTE(A1,3,""))-4*LEN(SUBSTITUTE(A1,4,""))+5*LEN(SUBSTITUTE(A1,5,""))-6*LEN(SUBSTITUTE(A1,6,""))+7*LEN(SUBSTITUTE(A1,7,""))-8*LEN(SUBSTITUTE(A1,8,""))+9*LEN(SUBSTITUTE(A1,9,""))-5*LEN(A1))

enter image description here

C#, 57 bytes

namespace System.Linq{i=>Math.Abs(i.Sum(n=>n%2<1?n:-n))}

Takes input as i and sums the integers by turning the odds to negative.

05AB1E, 7 bytes

È2*<*OÄ

Try it online!

        # Input              | 1234567
È       # Is Even?           | [0,1,0,1,0,1,0]
 2*<    # (a * 2) - 1        | [-1,1,-1,1,-1,1,-1]
    *   # Multiply w/ input. | [-1,2,-3,4,-5,6,-7]
     O  # Sum.               | -10
      Ä # Absolute value of. | 10

R, 30 29 bytes

abs(sum((d=scan())-2*d*d%%2))

d = scan() takes the input number by one digit after the other.

-1 byte thanks to @Giuseppe!

C#, 67 bytes

namespace System.Linq{a=>Math.Abs(a.Sum(n=>n%2<1)-a.Sum(n=>n%2>1))}

C#, 59 bytes

Math.Abs(a.Where(x=>(x%2<1)).Sum()-a.Where(x=>x%2>0).Sum())

Python 2, 39 bytes

Takes integer as list. Try it online

lambda A:abs(sum((-1)**i*i for i in A))

-3 bytes thanks to @Mr.Xcoder
-1 byte thanks to @ovs

Java (OpenJDK 8), 55 bytes

a->{int s=0;for(int d:a)s+=d%2<1?-d:d;return s<0?-s:s;}

Try it online!

Naive implementation.

><>, 32 bytes

00\~:00@(?$-n;
(?\c%:0@2%?$-+i:0

Try it online!

Bash 141 139 99 Bytes

while read -n1 a; do
[ $[a%2] = 0 ]&&e=$[e+a]||o=$[o+a]
done
(($[e-o]>0))&&echo $[e-o]||echo $[o-e]

Try it online!

Haskell, 47 42 39 38 26 25 bytes

-1 thanks to nimi

-12 thanks to Bruce

-1 thanks to xnor

abs.sum.map(\x->x*(-1)^x)

Try it online!

PHP, 54 bytes

for(;~$n=$argn[$i++];)${eo[$n&1]}+=$n;echo abs($e-$o);

Try it online!

PHP, 57 bytes

store the even and odd sums in an array

for(;~$n=$argn[$i++];)$r[$n&1]+=$n;echo abs($r[0]-$r[1]);

Try it online!

PHP, 57 bytes

store the even and odd sums in two variables

for(;~$n=$argn[$i++];)$n&1?$o+=$n:$e+=$n;echo abs($e-$o);

Try it online!

R, 72 43 bytes

b=(d=scan())%%2<1;abs(sum(d[b])-sum(d[!b]))

First, d = scan() takes the number as input, one digit after the other (thanks to @Giuseppe comment !)
Then, b = d %% 2 <1 associates to b a TRUE or FALSE value at each index depending on the digits' parity. Therefore, b values are TRUE for even numbers, and !b are TRUE for odd values.

Finaly, abs(sum(d[b]) - sum(d[!b])) does the job.

Braingolf, 18 bytes

{.2%?M|}&+v&+c-!s*

Try it online!

Takes input as a list of digits

Explanation

{.2%?M|}&+v&+c-!s*  Implicit input from commandline args
{......}            Foreach loop, runs on each item in the stack..
 .2%                ..Parity check, push 1 if odd, 0 if even
    ?               ..If last item != 0 (pops last item)..
     M              ....Move last item to next stack
      |             ..Endif
        &+          Sum entire stack
          v&+       Switch to next stack and sum entire stack
             c-     Collapse into stack1 and subtract
               !s   Sign check, push 1 if last item is positive, -1 if last item is
                    negative, 0 if last item is 0
                 *  Multiply last item by sign, gets absolute value
                    Implicit output

Mathematica, 67 bytes

(s=#;Abs[Subtract@@(Tr@Select[IntegerDigits@s,#]&/@{EvenQ,OddQ})])&

APL, 8 bytes

|⊢+.ׯ1*⊢

Try it online!

How?

¯1*⊢ - -1n for n in

[4 5 91 ¯1 ¯1]

⊢+.× - verctorized multiplication with o, then sum

[+/ 4 5 9 × 1 ¯1 ¯1+/ 4 ¯5 ¯9¯10]

| - absolute value

PHP, 51 bytes

while(~$n=$argn[$i++])$s+=$n&1?$n:-$n;echo abs($s);

adds digit to $s if odd, subtracts if even. Run as pipe with -nR.

or

while(~$n=$argn[$i++])$s+=(-1)**$n*$n;echo abs($s);

using Dennis´ -1 power trick.

C (gcc), 59 58 57 bytes

i;f(char*v){for(i=0;*v;v++)i+=*v%2?*v-48:48-*v;v=abs(i);}

Try it online!

05AB1E, 6 bytes

Thanks to Dennis for the -1 power trick. Takes input as a list of digits

®sm*OÄ

Try it online!

Explanation

®sm*OÄ                                               Example [4, 5, 9]
®      # Push -1                                   % STACK: -1
 sm    # Take -1 to the power of every number      % STACK: [1, -1, -1]
         in the input list 
   *   # Multiply with original input              % Multiply [1, -1, -1] with [4, 5, 9] results in STACK: [4, -5, -9]
    O  # Sum them all together                     % STACK: -10
     Ä # Absolute value                            % STACK: 10
       # Implicit print

Jelly, 6 bytes

-*æ.¹A

Try it online!

How it works

-*æ.¹A  Main link. Argument: A (digit array)

-*      Raise -1 to A's digits, yielding 1 for even digits and -1 for odd ones.
    ¹   Identity; yield A.
  æ.    Take the dot product of the units and the digits.
     A  Apply absolute value.

Husk, 7 bytes

≠0ṁṠ!¡_

Try it online!

Takes a list of digits as input.

Still missing an "abs" builtin, but a good result all the same :)

Explanation

Ṡ!¡_ is a function that takes a number n and then applies n-1 times the function _ (negation) to n. This results in n for odd n or -n for even n.

applies a function to each element of a list and sums the results.

≠0 returns the absolute difference between a number and 0.

Perl 6, 28 bytes

{abs sum $_ Z*.map(*%2*2-1)}

Try it online!

Takes a list of digits as input.

Neim, 7 bytes

ΓDᛃΞ𝐍}𝐬

Explanation:

Γ        Apply the following to each element in the input array
 D         Duplicate
  ᛃ        Modulo 2, then perform logical NOT
   Ξ       If truthy, then:
    𝐍        Multiply by -1
      }  Close all currently running loops/conditionals etc
       𝐬 Sum the resulting array

Julia 0.5, 19 bytes

!x=(-1).^x⋅x|>abs

Try it online!

Japt, 8 bytes

x_*JpZÃa

Test it online!

Explanation

 x_  *JpZÃ a
UxZ{Z*JpZ} a
                Implicit: U = list of digits
UxZ{     }      Take the sum of each item Z in U mapped through the following function:
      JpZ         Return (-1) ** Z
    Z*            times Z. This gives Z if even, -Z if odd.
           a    Take the absolute value of the result.
                Implicit: output result of last expression