Skip to content

Conversation

@Kyujenius
Copy link
Contributor

@Kyujenius Kyujenius commented Mar 2, 2025

I added sortedIndexOf in compat layer using by sortedIndex which is

Resolves: #846

import { sortedIndex } from './sortedIndex';

/**
 * This method is like `indexOf` but performs a binary search on a sorted array.
 * @param {ArrayLike<T> | null | undefined} array The sorted array to inspect.
 * @param {T} value The value to search for.
 * @returns {number} Returns the index of the matched value, else -1.
 * @example
 *
 * sortedIndexOf([4,5,5,5,6], 5) => 1
 * sortedIndexOf([1.1, 2.2, 3.3], 2.2) => 1
 *
 */
export function sortedIndexOf<T>(array: ArrayLike<T> | null | undefined, value: T): number {
  if (!array?.length) return -1;

  const index = sortedIndex(array, value);
  if (index < array.length && areValuesEqual(array[index], value)) return index;
  return -1;
}

const areValuesEqual = <T>(a: T, b: T): boolean => Object.is(a, b);

I conducted more extensive testing, comparing all results with the existing Lodash functions. My tests covered a wider range of scenarios, and in all cases, my implementation produced identical results to the original Lodash functions.

Test

Test List Test Coverage
스크린샷 2025-03-03 오전 3 02 29 스크린샷 2025-03-03 오전 3 02 57
Bench Test (It is 1.7x~ 1.8x faster than lodash )
benchTest

@Kyujenius Kyujenius requested a review from raon0211 as a code owner March 2, 2025 18:22
@vercel
Copy link

vercel bot commented Mar 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
es-toolkit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 15, 2025 3:33pm

@Kyujenius Kyujenius changed the title feat(compat): Implement sortedIndexOf feat(sortedIndexOf): Implement compat/sortedIndexOf Mar 2, 2025
@dayongkr
Copy link
Collaborator

Thank you for your contribution! I will review it within the weekend.

@Kyujenius
Copy link
Contributor Author

@dayongkr Of course! If there's anything incorrect or that needs to be fixed, please feel free to let me know! If possible, I'd love to contribute even more!

@dayongkr
Copy link
Collaborator

This seems to be your first contribution, and it's also my first review 😄 I can see that you put a lot of thought into your work!

If you plan to contribute more in the future, I recommend joining our Discord, where we actively communicate.

@Kyujenius
Copy link
Contributor Author

Thanks for inviting me ! 😄 It gives me strength!

Copy link
Collaborator

@dayongkr dayongkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The examples modifications are minor, so I will make the adjustments myself!

Welcome to your first contribution, and huge thanks!!

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.40%. Comparing base (9ed8885) to head (c914a58).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #971      +/-   ##
==========================================
+ Coverage   99.37%   99.40%   +0.03%     
==========================================
  Files         381      382       +1     
  Lines        3371     3378       +7     
  Branches     1002     1004       +2     
==========================================
+ Hits         3350     3358       +8     
+ Misses         20       19       -1     
  Partials        1        1              
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dayongkr dayongkr merged commit 4377dd9 into toss:main Mar 15, 2025
7 checks passed
@Kyujenius
Copy link
Contributor Author

@dayongkr
Thank you very much for letting me know one by one, and I was able to finish it. Thank you. 😢 💌 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add sortedIndexOf to compat package Support sortedIndex, sortedIndexBy, sortedIndexOf

3 participants