Get strings between two indexes
Thu Jun 17 2021 15:30:56 GMT+0000 (Coordinated Universal Time)
Saved by
@codeyad
#javascript
var getStart = function(index, text){
while(index > 0 && text[index] !== " "){
index--;
}
return index;
}
var getEnd = function(index, text){
while(index < text.length && text[index] !== " "){
index++;
}
return index;
}
var getSelectedWord = function(firstIndex, lastIndex, text){
return text.substring(getStart(firstIndex, text), getEnd(lastIndex, text)).split(' ');
}
content_copyCOPY
Comments