Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
Clasificación de matriz independientemente de mayúsculas o minúsculas

Estoy creando esta tubería de clasificación para mi proyecto angular. Pero sale así.

 "BUNNY", "Castle 111", "TOTAL 2323 Test", "Tower 2323 Test", "Vivy", "bayside"
Quiero ser [bayside,BUNNY,Castle 111,TOTAL 2323 Test,Tower 2323 Test,vivy] Aquí está mi fragmento de código de prueba https://codesandbox.io/s/orderbypipe-bc7xx?file=/src/app/app .componente.html:820-832

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Puede usar localeCompare con {sensitivity: 'accent'} en la devolución de llamada de sort para ignorar mayúsculas y minúsculas.

 const arr=["BUNNY", "Castle 111", "TOTAL 2323 Test", "Tower 2323 Test", "Vivy", "bayside"]; arr.sort((a,b)=>a.localeCompare(b, undefined, {sensitivity: 'accent'})); console.log(arr);

about 4 years ago · Juan Pablo Isaza Report

0

Puede comparar las dos cadenas convirtiéndolas a minúsculas (con String.toLowerCase ) y luego usando String.localeCompare :

 const arr = ["BUNNY", "Castle 111", "TOTAL 2323 Test", "Tower 2323 Test", "Vivy", "bayside" ] const sorted = arr.sort((a,b) => a.toLowerCase().localeCompare(b.toLowerCase())) console.log(sorted)

about 4 years ago · Juan Pablo Isaza Report

0

Puede aprovechar el método sortBy de la biblioteca lodash para ordenar la colección unidimensional independientemente del caso.

  • Instalar lodash y lodash-es
 npm install --save lodash npm install --save-dev @types/lodash
  • Modifique la tubería como se muestra en el siguiente fragmento,
 import { Pipe, PipeTransform } from "@angular/core"; import { sortBy } from "lodash-es"; @Pipe({ name: "sortBy" }) export class SortByPipe implements PipeTransform { transform<T>( value: T[], caseInsensitive = false, order = "", column: string = "" ): T[] { if (!column || column === "") { const sorted = this.sortOnCaseSensitivity(value, caseInsensitive); if (order === "asc") { return sorted; } else { return sorted.reverse(); } } if (value.length <= 1) { return value; } } sortOnCaseSensitivity<T>(value: T[], caseInsensitive: boolean): T[] { return sortBy(value, (v: T) => { if (typeof v === "string" && caseInsensitive) { return v.toLowerCase(); } return v; }); } }
  • Llame a la canalización personalizada sortBy creada en su archivo template.html como se muestra a continuación,
 <ul> <li *ngFor="let word of words | sortBy: true:'asc'">{{ word }}</li> </ul>

Para su referencia, agregue un enlace a una demostración de trabajo aquí

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!