toss / es-toolkit

A modern JavaScript utility library that's 2-3 times faster and up to 97% smaller—a major upgrade to lodash.
https://es-toolkit.slash.page
Other
6.28k stars 269 forks source link

Support for `pullAt` #418

Closed jiwooproity closed 2 weeks ago

jiwooproity commented 3 weeks ago

@raon0211 Hello! we meet again. sorry for posting issues so frequently.

/**
 * Returns index searched of original array and changed original array.
 *
 * @template T - The type of elements of array.
 * @param {T[]} array - The original array to pullAt.
 * @param {number[]} indexes - The array for index search of the original array to pullAt.
 * @returns {(T | undefined)[]} - A new array of pullAt result
 * @example
 * const array = ['%', { a: '2' }, '3', '5', '6'];
 * const result = pullAt(array, [1, 3]);
 * // result will be new array of pullAt result
 * // array: ['%', '3', '6'];
 * // result: [{ a: '2' }, '5']
 */
export function pullAt<T>(array: T[], indexes: number[]): (T | undefined)[] {
  const result: (T | undefined)[] = [];

  for (const index of indexes) {
    result.push(array[index]);
  }

  for (const value of result) {
    if (typeof value !== 'undefined' && array.includes(value)) {
      array.splice(array.indexOf(value), 1);
    }
  }

  return result;
}

https://lodash.com/docs/4.17.15#pullAt

Are there any plans to implement pullAt for this library? If you have plans for implement pullAt feature and agree to add it, i can work on it.

jonahisadev commented 3 weeks ago

I started working on this, but didn't have time to add the documentation before the weekend was up. In the next couple of days I can have a PR open for this.

jiwooproity commented 3 weeks ago

@jonahisadev Oh .. did you implemented this feature already? I thought it wasn't implemented yet. so i created issue and waiting review for this code 4 days ago.

jonahisadev commented 3 weeks ago

@jiwooproity I completely missed that you included an implementation snippet. A couple days ago I wrote an implementation and the test coverage for the function. I did not spend much time on it, so I can leave that to you if you'd like, but you should probably open a pull request with your changes instead of just leaving it as an issue.

jiwooproity commented 3 weeks ago

@jonahisadev Thank you for your advice! as you said i will open a pull request of my changes. I'm not yet familiar with contribution activities and i was wondering if i could open a pull request. I'm sorry for any confusion.

jonahisadev commented 3 weeks ago

@jiwooproity no need to apologize! it's my fault for the confusion. Your implementation looks good, and I think is benchmarking better than mine :)

jiwooproity commented 3 weeks ago

@jonahisadev Thank you for your kindly. It is energizing to be praised. Also, I had a good experience with contributing activities. have a good day!