About: Sort an Array of Strings Case-Insensitively   Sponge Permalink

An Entity of Type : owl:Thing, within Data Space : 134.155.108.49:8890 associated with source dataset(s)

By default, the Array.sort() method sorts strings case sensitively, so "B" will appear before "a" in the sorted array. This code snippit shows how to sort an Array of strings case insensitively. arr = new Array('Dog', 'cat', 'Mouse', 'frog', 'Turtle'); function sortCaseInsensitive(a, b) { if (a.toLowerCase() < b.toLowerCase()) return -1; if (a.toLowerCase() > b.toLowerCase()) return 1; return 0; } //Case sensitive - returns "Dog, Mouse, Turtle, cat, frog" print(arr.sort()); //Case insensitive - returns "cat, Dog, frog, Mouse, Turtle" print(arr.sort(sortCaseInsensitive));

AttributesValues
rdfs:label
  • Sort an Array of Strings Case-Insensitively
rdfs:comment
  • By default, the Array.sort() method sorts strings case sensitively, so "B" will appear before "a" in the sorted array. This code snippit shows how to sort an Array of strings case insensitively. arr = new Array('Dog', 'cat', 'Mouse', 'frog', 'Turtle'); function sortCaseInsensitive(a, b) { if (a.toLowerCase() < b.toLowerCase()) return -1; if (a.toLowerCase() > b.toLowerCase()) return 1; return 0; } //Case sensitive - returns "Dog, Mouse, Turtle, cat, frog" print(arr.sort()); //Case insensitive - returns "cat, Dog, frog, Mouse, Turtle" print(arr.sort(sortCaseInsensitive));
dcterms:subject
abstract
  • By default, the Array.sort() method sorts strings case sensitively, so "B" will appear before "a" in the sorted array. This code snippit shows how to sort an Array of strings case insensitively. arr = new Array('Dog', 'cat', 'Mouse', 'frog', 'Turtle'); function sortCaseInsensitive(a, b) { if (a.toLowerCase() < b.toLowerCase()) return -1; if (a.toLowerCase() > b.toLowerCase()) return 1; return 0; } //Case sensitive - returns "Dog, Mouse, Turtle, cat, frog" print(arr.sort()); //Case insensitive - returns "cat, Dog, frog, Mouse, Turtle" print(arr.sort(sortCaseInsensitive));
Alternative Linked Data Views: ODE     Raw Data in: CXML | CSV | RDF ( N-Triples N3/Turtle JSON XML ) | OData ( Atom JSON ) | Microdata ( JSON HTML) | JSON-LD    About   
This material is Open Knowledge   W3C Semantic Web Technology [RDF Data] Valid XHTML + RDFa
OpenLink Virtuoso version 07.20.3217, on Linux (x86_64-pc-linux-gnu), Standard Edition
Data on this page belongs to its respective rights holders.
Virtuoso Faceted Browser Copyright © 2009-2012 OpenLink Software