Giter VIP home page Giter VIP logo

nearby-sort's Introduction

Nearby Sort

This is very small and lightweight library that is capable to sort the given array by provided location coordinates.

Installation

Install nearby-sort with npm

  npm install nearby-sort // npm
  yarn add nearby-sort // yarn

Usage/Examples

Import

import nearbySort from 'nearby-sort'; // ES6
const nearbySort = require("nearby-sort"); // CommonJS

Data

// User's location
const coordinates = {
  lat: 31.442907,
  long: 74.271519,
};

// Array need to be sorted
const arr = [
  {
    name: 'Kudos',
    lat: 31.460443680085763,
    long: 74.26974289747655,
  },
  {
    name: 'Dr Hospital',
    lat: 31.480616187193373,
    long: 74.28008468009904,
  },
  {
    name: 'Steak Studio',
    lat: 31.446620698317826,
    long: 74.2704643576623,
  },
];

Usage

// Asc Sort
let ascSortedData = await nearbySort(coordinates, arr);

// Desc Sort
let descSortedData = await nearbySort(coordinates, arr, false);

Contributing

  • Fork it!
  • Create your feature branch: git checkout -b my-new-feature
  • Commit your changes: git commit -am 'Add some feature'
  • Push to the branch: git push origin my-new-feature
  • Submit a pull request :D

Author

nearby-sort © Yousuf
Authored and maintained by Yousuf Kalim.

GitHub @yousufkalim · LinkedIn @yousufkalim

License

MIT

nearby-sort's People

Contributors

yousufkalim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

nasyarobby

nearby-sort's Issues

Would anything speak against having also a synchronous version?

It's great to have this lib as async, it's efficient and it should work with any use case.

But it bloats a bit my db client wrappers which are all synchronous leading to interweaved and multiple awaits like with

await (await db()).select().from(users) // db needs to be called on every request

In contrast, it's good to have nearby-sort's calcs async and non-blocking.

Then again my array size is never more than a dozen. So, IDK if this trade-off, performance vs dev ux, is worth to think about a blocking version. What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.