菲波那切数列
function feibo(n){
return n<=2?1:feibo(n-1)+feibo(n-2)
}
水仙花数
function number(n){ if(n<100){ return } let result=[] for(let i=0;i<=n;i++){ let tempArr=i.toString().split(''); let count=tempArr .map(item=>Math.pow(item,tempArr.length)) .reduce((v1,v2)=>v1+v2); if(count==i){ result.push(i) } } return result }
简单BusEvent(发布订阅模式)
class Bus { event = {} $on(name, callback) { this.event[name] = callback } $emit(name, data) { if (this.event[name]) { this.event[name](data) } } } let bus = new Bus() bus.$on('test', res => { console.log(res); }) setTimeout(() => { bus.$emit('test', [1, 2, 3]) }, 1000);