Permalink
Browse files

added uniq() function

  • Loading branch information...
micha committed May 28, 2009
1 parent fe73c10 commit e5e73dd72017d0782280fbbd3f7115c297f5c940
Showing with 10 additions and 2 deletions.
  1. +6 −0 README.markdown
  2. +4 −2 jsawk
View
@@ -166,6 +166,12 @@ functions and properties are available from within a jsawk script:
params: Object|Array|Number|String thing (what to serialize)
return: String (the resulting JSON string)
+ uniq(array)
+ Return array of distinct elements.
+
+ params: Array array (the input array)
+ return: Array (the resulting array of distinct elements)
+
Q(query, thing)
Runs the JSONQuery 'query' on the JSON input 'thing'.
View
6 jsawk
@@ -184,7 +184,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2
for(var i=0,l=array.length; i<l; ++i){
var value = array[i];
if(callback(value, i, array)){
- if((typeof value == 'object') && value){
+ if((typeof value == 'object') && value) {
// with objects we prevent duplicates with a marker property
if(!value.__included){
value.__included = true;
@@ -205,6 +205,9 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2
}
return outArr;
}
+ window.uniq = function(array) {
+ return distinctFilter(array, function() { return true; });
+ };
var JSONQuery = function(/*String*/query,/*Object?*/obj){
// summary:
// Performs a JSONQuery on the provided object and returns the results.
@@ -995,7 +998,6 @@ replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
afters.push(makeFilter(argv.shift()));
break;
default:
- if (argv.length > 0) usage();
fun = arg;
}
}

0 comments on commit e5e73dd

Please sign in to comment.