138
rated 0 times
[
143]
[
5]
/ answers: 1 / hits: 37841
/ 8 Years ago, wed, august 17, 2016, 12:00:00
I am trying to write an algorithm for this in JavaScript but I am getting a str.length is not a function...
function extractMiddle(str) {
var position;
var length;
if(str.length() % 2 == 1) {
position = str.length() / 2;
length = 1;
} else {
position = str.length() / 2 - 1;
length = 2;
}
result = str.substring(position, position + length)
}
extractMiddle(handbananna);
More From » string