npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

logan-array-sort-ts

v1.0.4

Published

Sorting Array of types: String, Number, and Date using typescript

Downloads

4

Readme

The logan-array-sort-ts Package contains various methods for sorting arrays using TypeScript.

1. sortStringArray(arrayOfString: string[])

  • Takes one argument of array containing strings
  • Returns in alphabetical order, remember capital letters will be before lowercase
  • e.g. "Arial" will come before "arial"
  • ["Alphabet", "Car brand A", "Car brand B", "alphabet"]

2. sortNumberArray(arrayOfNumbers: number[])

  • Takes one argument of array containing numbers
  • Returns lowest number first
  • [100,22,34,47,58,61]

3. sortDateArray(arrayOfStringDates: Date[])

  • Takes Takes one argument of array containing dates
  • Date Patterns for string array: "YYYY-MM-DD"
  • Returns the earlist date first
  • ["YYYY-MM-DD", "YYYY-MM-DD", "YYYY-MM-DD", "YYYY-MM-DD"]

Example Output

String Array BEFORE Sorting:

[ 'Alphabet', 'alphabet', 'Car brand A', 'Car brand B' ]

String Array AFTER Sorting:

[ 'Alphabet', 'Car brand A', 'Car brand B', 'alphabet' ]

Number Array BEFORE Sorting:

[
  154, 229, 255, 201, 219, 171,  42, 170, 122, 170,  45, 250,
  103,  47,  45,  16, 145, 255, 226, 247,  19, 145,  45, 192,
  239, 245,  99, 221,  36, 151,  88, 186, 250,  22, 140, 250,
  233, 193, 180,  44,  71,  17, 194, 101,  79, 114, 206,  95,
   60, 153, 139,  71,   0,  94,   9, 100,  69, 160, 237,  91,
    5, 173, 229, 128,  49, 255,  27, 168, 187, 235, 233, 126,
   54, 101, 209, 153, 131, 241,  87,  89, 129,  24, 186,  64,
   60, 223, 206,  75,  98,  11, 192, 190,  84, 106, 108, 141,
  201, 147,  54,  73,
  ... 155 more items
]

Number Array AFTER Sorting:

[
    0,   0,   3,   5,  5,  9,  9,   9,   9,  10,  11,  12,
   15,  16,  16,  17, 17, 19, 20,  20,  20,  22,  23,  24,
   27,  27,  27,  29, 29, 31, 33,  33,  36,  36,  39,  41,
   42,  43,  44,  44, 45, 45, 45,  45,  47,  49,  51,  51,
  ... 155 more items
] 

Date Array After sorting:

[ '2000-01-01', 
  '2010-10-10', 
  '1850-08-26', 
  '1066-05-02' ] 

Date Array After Sorting:

[
  1066-05-02T00:00:00.000Z,
  1850-08-26T00:00:00.000Z,
  2000-01-01T00:00:00.000Z,
  2010-10-10T00:00:00.000Z
]