php - Equivalent of array_unique and preg_split PREG_SPLIT_NO_EMPTY -


i'm looking exact javascript equivalent of php:

$tags = preg_split('/+/', $_get['q'], null, preg_split_no_empty); $p = array_unique(array_map('strtolower', $tags)); sort($p); 

it's done

var querystring = decodeuricomponent(location.search.substring(1)).tolowercase();  var key = querystring.split('&')[0].split('='); if (key.length > 1){ //q should query key     var tags = key[1].split(/\+/g);     // make tags values unique, non-empty , ordered alphabetically } 

but i'm looking 3 things make tags values unique, non-empty , ordered alphabetically, it's done in php, hope there such solutions in js

thx

you can find on phpjs project:

code:

split: (explode dependency)

function split (delimiter, string) {     // http://kevin.vanzonneveld.net     // +   original by: kevin van zonneveld (http://kevin.vanzonneveld.net)     // -    depends on: explode     // *     example 1: split(' ', 'kevin van zonneveld');     // *     returns 1: {0: 'kevin', 1: 'van', 2: 'zonneveld'}     return this.explode(delimiter, string); } 

array_unique

function array_unique (inputarr) {     // http://kevin.vanzonneveld.net     // +   original by: carlos r. l. rodrigues (http://www.jsfromhell.com)     // +      input by: duncan     // +   bugfixed by: kevin van zonneveld (http://kevin.vanzonneveld.net)     // +   bugfixed by: nate     // +      input by: brett zamir (http://brett-zamir.me)     // +   bugfixed by: kevin van zonneveld (http://kevin.vanzonneveld.net)     // +   improved by: michael grier     // +   bugfixed by: brett zamir (http://brett-zamir.me)     // %          note 1: second argument, sort_flags not implemented;     // %          note 1: should sorted (asort?) first according docs     // *     example 1: array_unique(['kevin','kevin','van','zonneveld','kevin']);     // *     returns 1: {0: 'kevin', 2: 'van', 3: 'zonneveld'}     // *     example 2: array_unique({'a': 'green', 0: 'red', 'b': 'green', 1: 'blue', 2: 'red'});     // *     returns 2: {a: 'green', 0: 'red', 1: 'blue'}     var key = '',         tmp_arr2 = {},         val = '';      var __array_search = function (needle, haystack) {         var fkey = '';         (fkey in haystack) {             if (haystack.hasownproperty(fkey)) {                 if ((haystack[fkey] + '') === (needle + '')) {                     return fkey;                 }             }         }         return false;     };      (key in inputarr) {         if (inputarr.hasownproperty(key)) {             val = inputarr[key];             if (false === __array_search(val, tmp_arr2)) {                 tmp_arr2[key] = val;             }         }     }      return tmp_arr2; } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -