<$list filter="[tag[quote]sample[3]]">
<$transclude/>
</$list>
/*\
title: $:/filters/sample.js
type: application/javascript
module-type: filteroperator
Filter to return random set from the current list.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.sample = function(source,operator,options) {
var sampleIndex;
var allTitles = [];
var samples = [];
var numberOfSamples = parseInt(operator.operand) || 1;
source(function(tiddler,title) { allTitles.push(title); });
if (numberOfSamples >= allTitles.length) { return allTitles; }
for (var i = 0; i < numberOfSamples; i++) {
sampleIndex = Math.floor(Math.random() * allTitles.length);
samples = samples.concat(allTitles.splice(sampleIndex, 1));
}
return samples;
};
})();
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/7ad1fb46-382e-417c-a5a4-6e412274a2e8%40googlegroups.com.
One question,How about the performance effects? It seems when a tiddler uses this filter every change on the screen trigger the simple filter!Best wishesMohammad
To unsubscribe from this group and stop receiving emails from it, send an email to tiddl...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/21677588-663c-40ad-8292-745c5a2f0b18%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/1678c4fe-eb83-4ec7-8b88-087393253082%40googlegroups.com.