Giter Site home page Giter Site logo

asd-xiv / m Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 1.0 7.38 MB

Point free style, functional library for Javascript with focus on object arrays.

Home Page: https://asd-xiv.github.io/m/

License: MIT License

JavaScript 99.60% Shell 0.40%
functional javascript library point-free

m's People

Contributors

andreidmt avatar dgilperez avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

heartsradiant

m's Issues

Sort by date

I was wondering how to use sort / sortBy to sort by dates, which I believe is a common use case. I was about to open a PR but wanted to check your opinion first.

This is what I have, for sorting objects by a given field:

const sortByDate = field =>
  sort((a, b) => {
    if (isEmpty(b[field])) {
      return -1
    }

    if (isEmpty(a[field])) {
      return 1
    }

    return new Date(b[field]).getTime() - new Date(a[field]).getTime()
  })

which in turn takes me to consider other sorting behaviors (alphabetical?) and also if you'd add a new file for each sorting, or maybe generalize the criterium ...

About intersection

I was playing with intersection to see if that would allow us to find the elements in common in two arrays, but I am confused to see it does the opposite: it merges the two collections by applying a union function ... so my questions / comments:

  • I think current implementation is actually an union or join, not an intersection, in Venn's terms. If I'm not mistaken, I'd suggest a rename ... although that'd be a breaking change. Moreover when I'd suggest to add a different intersection function ...
  • Can intersection or other function in m be use to obtain that the elements in common in two lists? Would you accept a PR for that? What name would you give it?

About ESM and v7

Hi!

I upgraded to v7, ESM one, and I am fighting the upgrade.

I was under the wrong impression that changing const {x} = require("@asd14/m") to import {x} from "@asd14/m" would be enough, but I keep getting an require() of ES Module error importing the module. It seems that our Babel is taking that import and transforming it again to require, or something ...

... so my question would be if it makes sense to add upgrade instructions to the README, maybe considering this case.

Thanks!

Random pick

Hi! I was considering how to randomly pick one element from an array. Other langs have that direct method or an easy explicit combination, ie Ruby: array.shuffle.pop

I implemented this little one:

const pickRandom = items => items[Math.trunc(items.length * Math.random())]

Any alternative already here I did not find? Are you interested in a PR?

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.