Skip to content

Commit

Permalink
Chore: Simplify search code
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenwade committed May 20, 2021
1 parent cba69f2 commit 414766e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/source-code/token-store/utils.js
Expand Up @@ -23,15 +23,14 @@ function getStartLocation(token) {
//------------------------------------------------------------------------------

/**
* Binary-searches the index of the first token which is after the given location.
* Finds the index of the first token which is after the given location.
* If it was not found, this returns `tokens.length`.
* @param {(Token|Comment)[]} tokens It searches the token in this list.
* @param {number} location The location to search.
* @returns {number} The found index or `tokens.length`.
*/
exports.search = function search(tokens, location) {
const val = getStartLocation({ range: [location] });
const index = tokens.findIndex(el => val <= getStartLocation(el));
const index = tokens.findIndex(el => location <= getStartLocation(el));

return index === -1 ? tokens.length : index;
};
Expand Down

0 comments on commit 414766e

Please sign in to comment.