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.
- var cache = CacheService.getUserCache();
- function uniqueEach(input) {
- cache.put("unique", input); // drop input data into cache
- var input = cache.get("unique").toString().split(",").sort(); // receive input as 1D array and sort it
- var result = new Array();
- var cell = input[0]; // give initial value to avoid error
- result.push(cell);
- for (i in input) {
- if (cell != input[i]) {
- cell = input[i];
- result.push(cell);
- }
- }
- return result;
- }
Use CacheService to get a simple and fast bunch of data.
And sort make data processing more easy.
沒有留言:
張貼留言