# Challenge :

Inspired by Alphabet Position Finder

Given an string and one of two possible mathematical operator (+ or -) as input, your task is to return the operation of each alphabet position from the string.

# Example :

Input: "Hello World", "+"
=> "Hello World" = [8, 5, 12, 12, 15, 23, 15, 18, 12, 4] (converted to their equivalents)
=> sum alphabet positions = [8 + 5 + 12 + 12 + 15 + 23 + 15 + 18 + 12 + 4]
Output: 124


# Note :

• Ignore non-alphabetical characters
• You must use 1-indexing (a = 1, b = 2, ..., z = 26)
• If empty string submitted return a falsy value
• Operator can be taken as +/-. 1/-1, truthy/falsey, etc.

# Test Cases :

"Hello World", "-"             => -108
"I Love golfing", "+"          => 133
"She doesnt love you :(", "+"  => 224
"@#t%489/*-o", "-"             => 5
"", "-"                        => 0
"a", "-"                       => 1

• Comments are not for extended discussion; this conversation has been moved to chat.
– user45941
Commented Jun 10, 2018 at 20:23

# Java (JDK 10), 79 bytes

s->o->{int r=0,i=0;for(int c:s)r+=(c&=95)%32*(c>64&c<91?i++<1?1:o:0);return r;}


Try it online!

### Original answer before the question was clarified

Java (JDK 10), 46 bytes
s->o->s.chars().reduce(0,(a,b)->a+b%32*(44-o))


Try it online!

• Seems to fail for "to", "-" (expected 5, actual -35). Commented Jun 7, 2018 at 14:33
• @KevinCruijssen I give up on this answer. The requirements changed like the wind. This is valid with the very first version of the question, but not with the latest. Also, the test cases were not consistent. So I took the first two test cases and adapted them with the input given and made this answer. Commented Jun 7, 2018 at 14:36
• Seems the challenge is settled now.. I wish we could somehow enforce the use of the Sandbox for ALL challenges.. Anyway, adding .replaceAll("[^A-Za-z]","") takes care of one problem. The other problem is when the operator is - (it starts at the negative index of the first letter, instead of the positive value). I know some possible solutions, but all are pretty long.. Commented Jun 7, 2018 at 15:21
• @KevinCruijssen I just updated the answer based on the new question. Commented Jun 7, 2018 at 15:44

# Python 2, 70 66 bytes

lambda s,o:eval(o.join(ord(c)%32for c in s if c.isalpha())or'0')


Try it online!

# Japt v2.0a0, 12 13 bytes

+1 bytes to handle empty strings :(

r\L ¬®c uHÃrV


Try it

Original 12 byte version which would be valid if an error counts as a falsey value.

f\L ®c uHÃrV


Try it

## Explanation

                  :Implicit input of string U and operator string V
r                 :Remove
\L               : /[^a-z]/gi
¬             :Split
®            :Map
c           :  Character code
u         :  Modulo
H        :   32
Ã       :End map
rV     :Reduce by V


# Japt 2.0 -F0, 19 15 bytes

OvUf\l ®c %HÃqV


Test it online

## Explanation:

 OvUf\l ®c %HÃqV
Ov                 // Japt eval:
U                //   First input
f\l             //   Match [A-Za-z]
®    Ã      //   Map; At each item:
c          //     Char-Code
%H       //     %32
qV    //   Join with Second input (operator)
-F0                 // If the first input (string) is empty, output 0


# JavaScript (Node.js), 92 82 67 bytes

t=>o=>t?eval(t.match(/[a-z]/gi).map(x=>parseInt(x,36)-9).join(o)):0


Try it online!

# JavaScript (Node.js), 52 bytes

T=>_=>eval([...T].map(a=>a.charCodeAt()%32).join(_))


Try it online!

# Explanation :

T =>                            // first input for lambda function text (T)
_ =>                        // second input, the separator
eval(                   // evaluate a string
[...T]              // conver T into a comma separated array of its char
.map(a=>            // map over them a is representing the char
a.charCodeAt()  // a.charCodeAt(0)
% 32)       // find remainder of it when divided by 32
.join(_)        // and join them using the separator
)                       // end eval


# Note :

This completely ignores non-alphabetic words since the challenge seems to change after every two minutes, I chose this. (Can be changed if OP wants me to)

I posted this on the other challenge, just changed .join to .join(o) :

# JavaScript (Node.js), 57 bytes

t=>o=>t.match(/[a-z]/gi).map(i=>parseInt(i,36)-9).join(o)


Try it online!

# CJam, 24 bytes

q~el{'-_0>*}%{},0+':@+~


Try it online!

Could probably be more efficient, had to add 0 to the array to handle the empty string.

# 05AB1E, 9 bytes

áÇ32%Iý.E


Outputs nothing as falsey values if the input doesn't contain any letters.

No TIO, because .E isn't on TIO yet. Here an alternative version that does .E manually áÇ32%Iý“…¢(“s')J.e: Try it online or verify all test cases.

Explanation:

á        # Only keep letters of the first input-string
#  i.e. "Hello World" → "HelloWorld"
Ç       # Get the list of the unicode values of each letter
#  i.e. "HelloWorld" → [72,101,108,108,111,87,111,114,108,100]
32%    # modulo-32 each
#  i.e. [72,101,108,108,111,87,111,114,108,100] → [8,5,12,12,15,23,15,18,12,4]
Iý       # Join it with the operator input
#  [8,5,12,12,15,23,15,18,12,4] and "-" → "8-5-12-12-15-23-15-18-12-4"
.E     # Run it as Python-eval
#  i.e. "8-5-12-12-15-23-15-18-12-4" → -108


More details on the commit of .E, prove it works, and the alternative version here in a similar answer of mine.

# Jelly, 10 bytes

ŒuØAiⱮḟ0jV


Try it online!

# Explanation

ŒuØAiⱮḟ0jV  Main link
Œu          Uppercase the input
Ɱ      For each character
i       take its index in
ØA        the uppercase alphabet
ḟ0    Filter; remove 0s
j   String-join by the right element
V  Evaluate


-4 bytes thanks to Mr. Xcoder

• 9 bytes: ŒuØAiⱮjŒV or 8 bytes: ŒuØAiⱮjV if - can be taken as _ instead. Commented Jun 7, 2018 at 16:34
• @Mr.Xcoder oh that's actually shorter? cool thanks :D Commented Jun 7, 2018 at 16:43
• You don't need ḟ0`, as this outputs 0 for empty strings, doesn't it? Commented Jun 7, 2018 at 16:58
• @Mr.Xcoder non-alphabetical characters in the first position cause issues Commented Jun 7, 2018 at 22:12