npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yu-array

v1.0.1

Published

function for Array prototype

Downloads

3

Readme

yu-array

扩展Array.prototype函数

安装

npm install yu-array --save

引入

require('yu-array');
//或
import 'yu-array' 

Array.prototype.nextEach 同步手动遍历

/* 执行next才会遍历下一个元素 */
['a','b','c','d','e','f'].nextEach((val,i,next)=>{
	console.log(i);				//0,1,2,3,4,5
	next();				
})

/* 间隔n个元素 */
['a','b','c','d','e','f'].nextEach((val,i,next)=>{
	console.log(i);				//0,2,4
	next(1);	//间隔1个元素遍历
})

/* 从指定索引开始遍历 */
['a','b','c','d','e','f'].nextEach((val,i,next)=>{
	console.log(i);				//1,3,5
	next(1);	//间隔1个元素遍历
},1)		//从索引1开始遍历


/* 倒序 */
['a','b','c','d','e','f'].nextEach((val,i,next)=>{
	console.log(i);				//5,3,1
	next(1);	//间隔1个元素遍历
},1,true)		//倒序

Array.prototype.asyncNextEach 异步手动遍历,返回promise

/* 执行next才会遍历下一个元素 */
['a','b','c','d','e','f'].asyncNextEach((val,i,next)=>{
	console.log(i);				//0,1,2,3,4,5
	next();				
}).then(()=>{
	console.log('遍历完成')
})

/* 间隔n个元素 */
['a','b','c','d','e','f'].asyncNextEach((val,i,next)=>{
	console.log(i);				//0,2,4
	next(1);	//间隔1个元素遍历
})


/* 从指定索引开始遍历 */
['a','b','c','d','e','f'].asyncNextEach((val,i,next)=>{
	console.log(i);				//1,3,5
	next(1);	//间隔1个元素遍历
},1)		//从索引1开始遍历


/* 倒序 */
['a','b','c','d','e','f'].asyncNextEach((val,i,next)=>{
	console.log(i);				//5,3,1
	next(1);	//间隔1个元素遍历
},1,true)		//倒序

Array.prototype.timeoutEach 定时遍历,返回promise

/* 执行next才会遍历下一个元素 */
['a','b','c','d','e','f'].timeoutEach((val,i,next)=>{
	console.log(i);				//0,1,2,3,4,5
	next();				
}).then(()=>{
	console.log('遍历完成')
})

/* 设定遍历的间隔时间 */
['a','b','c','d','e','f'].timeoutEach((val,i,next)=>{
	console.log(i);				//0,1,2,3,4,5
	next();	
},1000)		//每隔1000毫秒遍历一个元素

/* 从指定索引开始遍历 */
['a','b','c','d','e','f'].timeoutEach((val,i,next)=>{
	console.log(i);			//1,2,3,4,5
	next();	
},1000,1)		//从索引1开始遍历

/* 倒序 */
['a','b','c','d','e','f'].timeoutEach((val,i,next)=>{
	console.log(i);				//5,4,3,2,1
	next();
},1000,1,true)		//倒序

/* 间隔n个索引 */
['a','b','c','d','e','f'].timeoutEach((val,i,next)=>{
	console.log(i);			//0,2,4
	next(1);	//间隔1个元素遍历
})

/* 指定遍历下一个元素的间隔时间 */
['a','b','c','d','e','f'].timeoutEach((val,i,next)=>{
	console.log(i);			//0,2,4
	next(1,500);	//500毫秒后遍历下一个
})

Array.prototype.ectypeEach 副本遍历 (创建该数组的副本,用来遍历)

/* val是副本的元素,i是副本的索引值 */
let arr = ['a','b','c','d','e','f'];
arr.ectypeEach((val,i)=>{
	console.log(i);		//0,1,2,3,4,5
	arr.splice(0);		//删除原数组不影响遍历
})

/* x是原数组的索引值 */
let arr1 = ['a','b','c','d','e','f'];
arr1.ectypeEach((val,i,x)=>{
	console.log(i);			//0,1,2,3,4,5
	i===2 && arr.splice(x,1);		//删除原数组不影响遍历
	console.log(x);			//0,1,2,2,3,4		x是当前元素在原数组的索引值
})

/* 倒序 */
['a','b','c','d','e','f'].ectypeEach((val,i,x)=>{
	console.log(i);			//5,4,3,2,1,0
},true)

Array.prototype.bubbling 冒泡排序

/* 顺序 */
[1,3,5,4,2].bubbling()	//[1,2,3,4,5]

/* 倒序 */
[1,3,5,4,2].bubbling(true)	//[5,4,3,2,1]

Array.prototype.select 选择排序

/* 顺序 */
[1,3,5,4,2].select()	//[1,2,3,4,5]

/* 倒序 */
[1,3,5,4,2].select(true)	//[5,4,3,2,1]

Array.prototype.insertion 插入排序

/* 顺序 */
[1,3,5,4,2].insertion()		//[1,2,3,4,5]

/* 倒序 */
[1,3,5,4,2].insertion(true)		//[5,4,3,2,1]

Array.prototype.quick 快速排序

/* 顺序 */
[1,3,5,4,2].quick()		//[1,2,3,4,5]

/* 倒序 */
[1,3,5,4,2].quick(true)		//[5,4,3,2,1]