1 function extractMiddle(str) {
2
3 var position;
4 var length;
5
6 if(str.length % 2 == 1) {
7 position = str.length / 2;
8 length = 1;
9 } else {
10 position = str.length / 2 - 1;
11 length = 2;
12 }
13
14 return str.substring(position, position + length)
15 }
16
17 console.log(extractMiddle("handbananna"));