2015年11月25日 星期三

Custom Functions Unique()

Original Function Unique() returns each columns's unique rows in the provided source range.

This script return unique data in provided source range (in each cells) . Rows are returned and sorted.


  1. var cache = CacheService.getUserCache();
  2. function uniqueEach(input) {  
  3.   cache.put("unique", input); // drop input data into cache
  4.   var input = cache.get("unique").toString().split(",").sort(); // receive input as 1D array and sort it
  5.   var result = new Array();
  6.   var cell = input[0]; // give initial value to avoid error
  7.   result.push(cell);
  8.   for (i in input) {
  9.     if (cell != input[i]) {
  10.       cell = input[i];
  11.       result.push(cell);
  12.     }
  13.   }
  14.   return result;
  15. }
Use CacheService to get a simple and fast bunch of data.
And sort make data processing more easy.

沒有留言:

張貼留言