输入
function fibonacci(n) { if (n <= 1) return n; return fibonacci(n - 1) + fibonacci(n - 2); } function processData(data) { // 处理数据:过滤、映射并排序 return data .filter(item => item.active) .map(item => ({ id: item.id, name: item.name.toUpperCase(), timestamp: new Date(item.createdAt) })) .sort((a, b) => b.timestamp - a.timestamp); } class DataProcessor { constructor(config) { this.config = config; this.cache = new Map(); } async process(input) { if (this.cache.has(input)) { return this.cache.get(input); } const result = await this.transform(input); this.cache.set(input, result); return result; } transform(data) { return new Promise((resolve) => { setTimeout(() => { resolve(data.map(x => x * 2)); }, 100); }); } }
高亮预览