Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c74ced

Browse files
committed
Fix ESLint issues with MergeSort.
1 parent83978e9 commit2c74ced

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

‎src/algorithms/sorting/merge-sort/MergeSort.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
importSortfrom"../Sort";
1+
importSortfrom'../Sort';
22

33
exportdefaultclassMergeSortextendsSort{
44
sort(originalArray){
@@ -26,38 +26,33 @@ export default class MergeSort extends Sort {
2626
mergeSortedArrays(leftArray,rightArray){
2727
constsortedArray=[];
2828

29-
// Use array pointers to exclude old elements after they have been added to the sorted array
29+
// Use array pointers to exclude old elements after they have been added to the sorted array.
3030
letleftIndex=0;
3131
letrightIndex=0;
3232

3333
while(leftIndex<leftArray.length&&rightIndex<rightArray.length){
34-
// Find the minimum element between the left and right array
35-
if(
36-
this.comparator.lessThanOrEqual(
37-
leftArray[leftIndex],
38-
rightArray[rightIndex]
39-
)
40-
){
41-
sortedArray.push(leftArray[leftIndex]);
34+
letminElement=null;
4235

36+
// Find the minimum element between the left and right array.
37+
if(this.comparator.lessThanOrEqual(leftArray[leftIndex],rightArray[rightIndex])){
38+
minElement=leftArray[leftIndex];
4339
// Increment index pointer to the right
4440
leftIndex+=1;
45-
46-
// Call visiting callback.
47-
this.callbacks.visitingCallback(leftArray[leftIndex]);
4841
}else{
49-
sortedArray.push(rightArray[rightIndex]);
50-
42+
minElement=rightArray[rightIndex];
5143
// Increment index pointer to the right
5244
rightIndex+=1;
53-
54-
// Call visiting callback.
55-
this.callbacks.visitingCallback(rightArray[rightIndex]);
5645
}
46+
47+
// Add the minimum element to the sorted array.
48+
sortedArray.push(minElement);
49+
50+
// Call visiting callback.
51+
this.callbacks.visitingCallback(minElement);
5752
}
5853

59-
// There will beone element remaining from either the left OR the right
60-
// Concatenate the remainingelement into the sorted array
54+
// There will beelements remaining from either the left OR the right
55+
// Concatenate the remainingelements into the sorted array
6156
returnsortedArray
6257
.concat(leftArray.slice(leftIndex))
6358
.concat(rightArray.slice(rightIndex));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp