Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

219
Vistas
functional non-destructive array sort

Apart for the native way of cloning an array and then sorting it in place, is there an algorithm and existing implementation that is more suited for non-destructive sorting?

Need to sort an array of floats into a new array without changing the source. My search results were rather thin since most of the literature is focused on reducing the memory requirements with in-place sorting.

Using the native sorted = [].slice().sort() works fine. This question is about understanding if there are other performant sorting implementations when memory constraints are removed since a new array is needed anyway.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

There's a simpler syntax for immutably sorting an array using ES6 spread operator:

[...array].sort(sortFn)
over 4 years ago · Santiago Trujillo Denunciar

0

As the comments have repeated a few times:

  1. shuffledArray.slice().sort() is the default way to go.
  2. It's not really clear how we could have a better algorithm / method using the libraries your mentioned.

Seeing as the motivation for non-destructive sorting is related to writing functional code, and you're looking at Ramda...check out Facebook's ImmutableJS library if you haven't already.

Particularly, the Seq. You could start storing your array of floats in a Seq, sort it, and be sure the original Seq remains in the right order. In addition, it utilizes Lazy evaluation. http://facebook.github.io/immutable-js/docs/#/Seq
http://facebook.github.io/immutable-js/docs/#/Seq/sortBy

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda