Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I just made the code more simple. It works exactly the same but now it's more readable, and the cpu has to make fewer calculations.
Let's compare:
If newNode is defined, then it resolves to:
If newNode is undefined, it resolves to:
Then, it is more readable to write it like this:
Then there's the other line:
Let's break it. When newNode is defined, it resolves to:
Which is equivalent to:
Now, when newNode is defined,
textIndexOfEndOfFarthestNode
will be equal tocurrentTextIndex + currentNode.nodeValue.length + newNode.nodeValue.length - 1;
So we replace:
We remove parenthesis:
We can simplify because we have
newNode.nodeValue.length - newNode.nodeValue.length
and1 - 1
, which both equal to0
.Finally, we rearrange the elements.
What if newNode is undefined?
Now
textIndexOfEndOfFarthestNode
will becurrentTextIndex + currentNode.nodeValue.length - 1
.And simplifying we got:
So,
endSplitPoint
can be defined as:If you think about it, you'll be able to understand it's logic. It is not an essential change. It only makes things slightly more simple and avoids headaches when trying to understand. It also makes it easier for the CPU.