Does the nth char equal the nth from last char? Inspired by Does the start equal the end
Given a string s and an integer n, output a truthy/falsey as to whether the nth char in s equals the nth from the end char in s.
Input
A non-empty string and an integer. You can use 0-based indexing or 1-based indexing. The integer is guaranteed to be valid based on the string. For example, if the string is &quot;supercalifragalistic123&quot;, the integer can be from 1 to 23 for 1-based indexing, and 0 to 22 for 0-based indexing. Please note that n can be larger than half the length of s.
Input is limited to printable ASCII.
Output
A truthy/falsey value based on whether the nth value in s equals the nth from last value in s.
Please note that the last char is in position 0 for 0-based indexing and position 1 for 1-based indexing. Think of it as comparing the string to its reverse.
Test Cases
0-indexed
&quot;1&quot;, 0         Truthy 1 == 1
&quot;abc&quot;, 1       Truthy b == b
&quot;aaaaaaa&quot;, 3   Truthy a == a
&quot;[][]&quot;, 1      Falsey ] != [
&quot;[][]&quot;, 0      Falsey [ != ]
&quot;ppqqpq&quot;, 2    Truthy q == q
&quot;ababab&quot;, 5    Falsey a != b
&quot;12345&quot;, 0     Falsey 1 != 5
&quot;letter&quot;, 1    Truthy e == e
&quot;zxywv&quot;, 3     Falsey w != x

1-indexed
&quot;1&quot;, 1         Truthy 1 == 1
&quot;abc&quot;, 2       Truthy b == b
&quot;aaaaaaa&quot;, 4   Truthy a == a
&quot;[][]&quot;, 2      Falsey ] != [
&quot;[][]&quot;, 1      Falsey [ != ]
&quot;ppqqpq&quot;, 3    Truthy q == q
&quot;ababab&quot;, 6    Falsey a != b
&quot;12345&quot;, 1     Falsey 1 != 5
&quot;letter&quot;, 2    Truthy e == e
&quot;zxywv&quot;, 4     Falsey w != x
JavaScript (ES6), 26 bytes

s=&gt;n=&gt;s[n]==s.substr(~n,1)


Alternatively:

s=&gt;n=&gt;s[n]==s.slice(~n)[0]


This one almost works, but fails when n == 0 (because s.slice(-1,0) == ""):

s=&gt;n=&gt;s[n]==s.slice(~n,-n)


Another 26-byte solution that @RickHitchcock pointed out:

s=&gt;n=&gt;s[n]==s[s.length+~n]