Code Monkey home page Code Monkey logo

old-norse-alphabet-sort's Introduction

Old Norse Alphabet Sort

Sort arrays by Old Norse alphabet in Node.js.

Usually localeCompare() or Intl.Collator() is enough to get alphabetical order, but there are edge cases like Icelandic and Old Norse alphabets. LocaleCompare seems to have hard time properly telling apart letters like a, æ or á. This package provides custom sorter for getting old norse alphabetical order just right.

Depends on Old Norse Alphabet package.

Install

yarn add old-norse-alphabet-sort

Usage

With simple arrays:

const { oldNorseSort } = require('old-norse-alphabet-sort')

const words = ['öðli', 'ógnan', 'æðrask', 'aðili', 'þakkan', 'áfir', 'él-ligr', 'ef-lauss', 'œgir', 'maðr']

const sortedWords = [...words].sort((a, b) => oldNorseSort(a, b))
// ['aðili', 'áfir', 'ef-lauss', 'él-ligr', 'maðr', 'ógnan', 'þakkan', 'æðrask', 'œgir', 'öðli']

With arrays of objects:

const { oldNorseSort } = require('old-norse-alphabet-sort')

const words = [
  {
    word: 'æðrask',
    definitions: [...]
  },
  {
    word: 'af-burðr',
    definitions: [...],
  }
]

const sortedWords = [...words].sort((a, b) => oldNorseSort(a.word, b.word))

About Old Norse

Old Norse was a North Germanic language that was spoken by inhabitants of Scandinavia and their overseas settlements from about the 7th to the 15th centuries.

old-norse-alphabet-sort's People

Contributors

dependabot[bot] avatar stscoundrel avatar

Stargazers

 avatar

Watchers

 avatar  avatar

old-norse-alphabet-sort's Issues

After first letter sorting is not correct

const words = ['Mælingar', 'Minnisatriði']
Sorted array should be ['Minnisatriði', 'Mælingar'], but it stays the same.

This on the other hand sorts correctly:
['ælingar', 'innisatriði'] => ['innisatriði', 'ælingar']

Special characters can mess sorting

Sorting something like "adal" with "adal-" can mess with sort, as "-" is not part of the alphabet. Add condition for not-found characters

Also, for "is same word" comparison use lowercase.

Add rarely used letters

Letters like "x" and "z" are not commonly part of ON alphabet, but they appear on some words. Add them to sorting algo

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.