I know this is weird! But why does this not work?
function getStringLength(string) {
var subString = string.slice();
var counter = 0;
while (subString !== '') {
counter++;
subString = subString.slice(counter);
}
return counter;
}
var output = getStringLength('hello');
console.log(output);
I really want to do this with a piece! The initial task was not to use the length property, and I figured it out that works great:
function getStringLength(string) {
var long = 0;
while (string[long] !== undefined) {
long++;
}
return long;
}
source
share