Skip to content

Commit

Permalink
reducing cognitive complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
zsmoore committed Dec 30, 2017
1 parent e8bec90 commit c61ec22
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/analyze/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,27 @@ function formatOutput(currTok, tokValue, tokenizer) {
}

function getNearestTok(tokens, aString) {
let endTok = 0;
let startTok = Number.MAX_SAFE_INTEGER;
let tokValue, currTok = "";
let values = {
endTok : 0,
startTok : Number.MAX_SAFE_INTEGER,
tokValue : "",
currTok : ""
};

for (let key in tokens) {
let tempArr = aString.match(tokens[key]);
if (tempArr !== null
&& (tempArr['index'] < startTok
|| (tempArr['index'] === startTok && tempArr[0].length > endTok))) {
startTok = tempArr['index'];
endTok = tempArr[0].length;
tokValue = tempArr[0];
currTok = key;
}
for (let key in tokens) {
let tempArr = aString.match(tokens[key]);
values = updateValues(tempArr, values, key);
}
return { 'endTok': endTok, 'startTok': startTok, 'tokValue': tokValue, 'currTok': currTok };
return values;
}

function updateValues(tempArr, values, key) {
if (tempArr != null && (tempArr['index'] < values.startTok
|| (tempArr['index'] === values.startTok && tempArr[0].length > values.endTok))) {
values.startTok = tempArr['index'];
values.tokValue = tempArr[0];
values.endTok = tempArr[0].length;
values.currTok = key;
}
return values
}

0 comments on commit c61ec22

Please sign in to comment.