Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD sortedIndex.md] #440

Merged
merged 7 commits into from Dec 31, 2017
Merged

[ADD sortedIndex.md] #440

merged 7 commits into from Dec 31, 2017

Conversation

rohitanwar
Copy link
Contributor

@rohitanwar rohitanwar commented Dec 31, 2017

Description

Lodash[ADD] #100 -> https://lodash.com/docs/4.17.4#sortedIndex

What does your PR belong to?

  • Website
  • Snippets
  • General / Things regarding the repository (like CI Integration)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking improvement of a snippet)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Lodash Backlog

  • I added the prefix [UPDATE: method.md] or [ADD: method.md]
  • I have referenced the method to the lodash backlog.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have checked that the changes are working properly
  • I have checked that there isn't any PR doing the same
  • I have read the CONTRIBUTING document.

@Chalarangelo Chalarangelo changed the title [ADD sortedIndex.md] [FIX : #100] [ADD sortedIndex.md] Dec 31, 2017

```js
const sortedIndex = (arr,n) => {
arr[0] > arr[1] ? (anarray = arr.reverse(),isReversed = true) : (anarray = arr,isReversed = false);

This comment was marked as spam.

This comment was marked as spam.

const sortedIndex = (arr,n) => {
arr[0] > arr[1] ? (anarray = arr.reverse(),isReversed = true) : (anarray = arr,isReversed = false);
val = anarray.findIndex( el => {
return n <= el

This comment was marked as spam.

@atomiks
Copy link
Contributor

atomiks commented Dec 31, 2017

There is no need to reverse the array. The following will be faster:

const sortedIndex = (arr, n) => {
  const isDescending = arr[0] > arr[arr.length - 1];
  const index = arr.findIndex(el => isDescending ? n >= el : n <= el);
  return index === -1 ? arr.length : index;
};

@Chalarangelo
Copy link
Owner

@atomiks Had the same thoughts, I just fixed these problems! 😆

@Chalarangelo
Copy link
Owner

@atomiks I like your approach, it also seems a lot faster!

@rohitanwar
Copy link
Contributor Author

@atomiks @Chalarangelo Updated it.

Copy link
Owner

@Chalarangelo Chalarangelo left a comment

Choose a reason for hiding this comment

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

Great job on adding this, thanks yet again for contributing!

@Chalarangelo Chalarangelo merged commit f0c246d into Chalarangelo:master Dec 31, 2017
@lock
Copy link

lock bot commented Dec 18, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for any follow-up tasks.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 18, 2019
Chalarangelo added a commit that referenced this pull request May 1, 2023
Update combine_values.md
Fixes #439
Closes #440
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants