# Implement a URL shortener

## JavaScript (ES6), 149 bytes

u=>u.split/.map((p,i)=>i?/^\d+$/.test(p)?(+p).toString(36):p[0]:(d=p.split.).slice(0,-1).map((s,j)=>s[l=j,0]).join+"."+d[l].slice(1,3)).join/ ### Explanation I made this independent of @Neil's solution but it ended up looking very similar. u=> u.split/.map((p,i)=> // for each part p at index i i? // if this is not the first part /^\d+$/.test(p)?         // if p is only digits
(+p).toString(36)      // return p as a base-36 number
:p[0]                    // else return the first letter
:
(d=p.split.)           // d = domain parts
.slice(0,-1).map((s,j)=> // for each domain part before the last
s[l=j,0]               // return the first letter, l = index of last domain part
).join
+"."+d[l].slice(1,3)     // add the 2 letters as the final domain
)
.join/                     // output each new part separated by a slash

### Test

var solution = u=>u.split/.map((p,i)=>i?/^\d+\$/.test(p)?(+p).toString(36):p[0]:(d=p.split.).slice(0,-1).map((s,j)=>s[l=j,0]).join+"."+d[l].slice(1,3)).join/
<input type="text" id="input" value="math.stackexchange.com/a/2231/" />
<button onclick="result.textContent=solution(input.value)">Go</button>
<pre id="result"></pre>