Этот код получает 242 страны в Sun Java 6:
String[] countryCodes = Locale.getISOCountries();
, Хотя веб-сайт ISO требования там 249 элементы кода ISO 3166-1-alpha-2 , хотя javadoc связывается с той же информацией.
Well internally inArray
makes a simple loop, I would recommend you to check if there is a native Array.prototype.indexOf
implementation and use it instead of inArray
if available:
function findPoint(point, list) {
var l = list.map(function anonMapToId(p) { return p.id });
var found = ('indexOf' in Array.prototype) ? l.indexOf(point.id)
: jQuery.inArray(point.id, l);
return found;
}
The Array.prototype.indexOf
method has been introduced in browsers that implement JavaScript 1.6, and it will be part of the ECMAScript 5 standard.
Native implementations are way faster than non native ones.
Even is the inArray
function were slow, you're still creating a full new array for every search. I suppose it would be better to redesign this search, by e.g. creating the id-list before finding the points, and using that one to search into: