日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python 构件二维数组_通过这四个构件块来升级您的javascript数组

發(fā)布時間:2023/12/20 python 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 构件二维数组_通过这四个构件块来升级您的javascript数组 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

python 構(gòu)件二維數(shù)組

Arrays in JavaScript are something special, as they leverage the prototype feature of JS and provide a handy way to run functions directly from a reference to an array instance.

JavaScript中的數(shù)組很特別,因為它們利用了JS的原型功能,并提供了一種便捷的方法來直接從引用到數(shù)組實例運行函數(shù)。

I believe that using these four functions as much as possible within your code will not only make you more efficient, but also make you more popular on your team and generally more amazing at what you do.

我相信,在您的代碼中盡可能多地使用這四個功能不僅會提高您的效率,而且還會使您在團隊中更受歡迎,并且通常會使您的工作更加驚奇。

All four of these prototype functions accept a “callback” function, which is a pure function that accepts arguments and must return something expected back to the caller, whether it be a boolean liketrue or false, or a type like String, Object, Array, or Number.

所有這四個原型函數(shù)都接受一個“回調(diào)”函數(shù),這是一個純函數(shù),它接受參數(shù)并且必須將期望的值返回給調(diào)用者,無論它是boolean如true或false )還是類型(如String , Object , Array或Number 。

Let’s take a look at each of these useful Array functions and learn to make our code more concise!

讓我們看一下這些有用的Array函數(shù),并學(xué)習(xí)使我們的代碼更簡潔 !

地圖— Array.prototype.map() (Map — Array.prototype.map())

Photo by Louis Hansel @shotsoflouis on Unsplash Louis Hansel的照片@shotsoflouis在Unsplash上

map is a building block of most programming languages, and is definitely a wonderful Array function to start with.

map是大多數(shù)編程語言的構(gòu)建塊,并且絕對是一個很棒的Array函數(shù)。

This line of code for instance, will loop through ANIMALS and create an array of Strings, with their name and animal type:

例如,以下代碼行將遍歷ANIMALS并創(chuàng)建Strings數(shù)組,其名稱和動物類型為:

You might already be familiar with map if you are using front-end frameworks like React or Vue where you quite often need to loop through an array of data to produce HTML:

如果您使用的是React或Vue等前端框架,那么您可能已經(jīng)很熟悉map ,在這些框架中,您經(jīng)常需要遍歷數(shù)據(jù)數(shù)組以生成HTML:

<ul>
{ANIMALS.map((animal) =>
<li>
{animal.name} ({animal.type})
</li>
)}
</ul>
?
// produces:
<ul>
<li>Spot (dog)</li>
<li>Fluffy (cat)</li>
<li>Peppy (bird)</li>
<li>Lizzy (lizard)</li>
</ul>

The map function is all-around useful to convert array of something X into array of something Y.

map函數(shù)可用于將X數(shù)組轉(zhuǎn)換為Y數(shù)組 。

Reduce — Array.prototype.reduce() (Reduce — Array.prototype.reduce())

The reduce function is used like map but takes it even further.

reduce函數(shù)的用法與map一樣,但功能更進一步。

Instead of convert array of something X into array of something Y, reduce is designed to convert array of something X into something Y, meaning you are not limited to just making a new array.

reduce不是將X的數(shù)組轉(zhuǎn)換為Y的數(shù)組,而是設(shè)計了將X的數(shù)組轉(zhuǎn)換為Y的意思,這意味著您不僅限于制作新的數(shù)組

You can turn an array into Objects, Numbers, or Strings. Here we sum up the total weight of all of the ANIMALS:

您可以將數(shù)組轉(zhuǎn)換為Objects , Numbers或Strings 。 在這里,我們總結(jié)所有ANIMALS的總重量:

reduce is such a powerful function on arrays, that it is versatile enough to produce the same effect as a map does. Check out this reduce version of a map function:

reduce是數(shù)組上如此強大的功能,它具有足夠的通用性,可以產(chǎn)生與map相同的效果。 看看這個map函數(shù)的reduce版本:

篩選器— Array.prototype.filter() (Filter — Array.prototype.filter())

Photo by Caleb Dow on Unsplash Caleb Dow在Unsplash上拍攝的照片

filter works just as it sounds, and only retrieves items from an array that produce a truthy value from your callback function. Here we look for ANIMALS that have soft fur or feathers:

filter工作原理與聽起來一樣,僅從可從回調(diào)函數(shù)產(chǎn)生真實值的數(shù)組中檢索項目。 在這里,我們尋找具有柔軟皮毛或羽毛的ANIMALS :

Here is another example, using a mathematical comparison. As long as the function returns a truthy/falsy value it works as expected. Here we only select ANIMALS that weigh less than 10lbs:

這是另一個使用數(shù)學(xué)比較的例子。 只要函數(shù)返回真實/虛假值,它就會按預(yù)期工作。 在這里,我們只選擇重量小于10磅的ANIMALS :

查找— Array.prototype.find() (Find — Array.prototype.find())

Finally, we have find, which helps you search through an array using a callback. This is extremely useful as it provides an interface to search through an array that also works with a sister function called findIndex.

最后,我們find ,它可以幫助您使用callback遍歷數(shù)組。 這非常有用,因為它提供了一個搜索數(shù)組的接口,該數(shù)組也可以與名為findIndex的姊妹函數(shù)findIndex 。

As long as your function returns a truthy value, the first truthy value returned will exit the find search and return back that row from the array.

只要您的函數(shù)返回真實值,返回的第一個真實值將退出find搜索并從數(shù)組中返回該行。

In this example, we find a dog named Spot:

在此示例中,我們find了一只名為Spot的狗:

組合數(shù)組函數(shù) (Combining Array Functions)

Photo by Ali Yahya on Unsplash Ali Yahya在Unsplash上拍攝的照片

Now that you have a handle on these four building block functions, we can combine them all together:

現(xiàn)在您已經(jīng)掌握了這四個構(gòu)建基塊函數(shù),我們可以將它們?nèi)拷M合在一起:

Above, we first map over our ANIMALS and create a new object of their weight and type, also taking this opportunity to feed each one. We feed them and they might gain about 1% of their body weight after eating - this is just a guess.

上面,我們首先在ANIMALS map ,并創(chuàng)建一個重量類型相同的新對象,并借此機會喂食每個ANIMALS 。 我們喂養(yǎng)他們,他們進食后可能會增加體重的1%-這只是一個猜測。

Then we filter out only animals that have fur or feathers, notice we did this after feeding, since we don’t want to starve our lizard Lizzy 🦎:

然后我們只過濾出有毛皮或羽毛的動物,請注意,喂食后我們這樣做了,因為我們不想餓死蜥蜴Lizzy🦎:

.filter((animal) => animal.type !== 'lizard') // only soft

.filter((animal) => animal.type !== 'lizard') // only soft

Then we filter out animals over a certain weight limit, which removes the dog’s entry 🐕:

然后我們篩選出超過一定重量限制的動物,從而刪除狗的入口🐕:

.filter((animal) => animal.weight < 10) // only light (after eating)

.filter((animal) => animal.weight < 10) // only light (after eating)

Finally, we reduce the remaining animal rows into a single value, a number representing their weight 🐈🐦:

最后,我們將剩余的動物行簡化為一個值,該數(shù)字代表它們的權(quán)重🐈🐦:

.reduce((weightSum, animal) => weightSum + animal.weight, 0); // get total weight

.reduce((weightSum, animal) => weightSum + animal.weight, 0); // get total weight

All of this is easily and flawlessly chained together thanks to Array prototypes and JavaScript magic.

借助Array原型和JavaScript魔術(shù),所有這些都可以輕松,完美地鏈接在一起。

翻譯自: https://levelup.gitconnected.com/level-up-your-javascript-arrays-with-these-four-building-block-functions-d01ca0971bcf

python 構(gòu)件二維數(shù)組

總結(jié)

以上是生活随笔為你收集整理的python 构件二维数组_通过这四个构件块来升级您的javascript数组的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 午夜免费影院 | 国产精品久久一 | 亚洲电影一区二区三区 | 日韩精品――中文字幕 | 亚洲性片 | 欧美日本在线播放 | 老鸭窝av在线 | 成人毛片100部免费看 | www.波多野结衣.com | 国产精品一级片在线观看 | 香蕉视频二区 | 国产ts系列 | 婷婷.com| 日韩精品国产一区 | 国产人妻777人伦精品hd | 精品999久久久一级毛片 | 香蕉网在线视频 | 亚洲成a人片在线 | 美女一区二区三区视频 | 女人被狂躁c到高潮 | 国产精品久久久久不卡 | 中国特级黄色大片 | 影音先锋国产在线 | 久久久久久成人精品 | 韩国黄色片网站 | 国产精品精品 | 日韩中文字| 催眠调教后宫乱淫校园 | 久久艳片www.17c.com | 欧美一级视频在线观看 | 色天堂视频 | 福利小视频在线观看 | 强行糟蹋人妻hd中文字幕 | 国产在线麻豆 | 久久亚洲AV成人无码国产野外 | 杨幂毛片| 欧美123区 | 男女啪啪毛片 | av午夜激情 | 日韩一区二区免费看 | 欧美综合国产 | 国产熟妇一区二区三区aⅴ网站 | 亚洲午夜精品久久久久久人妖 | 亚洲国产一区二区在线观看 | 欧美巨大荫蒂茸毛毛人妖 | 日本久久一级片 | 国产亚洲精久久久久久无码77777 | www.色哟哟| 欧美 日韩 国产 中文 | 亚洲欧美在线视频观看 | 国产在线精品成人欧美 | 精品亚洲aⅴ无码一区二区三区 | www欧美视频 | 久久女人| 九九久久免费视频 | www.欧美在线观看 | 日韩av在线一区二区三区 | 久久青青草原亚洲av无码麻豆 | 亚洲精品乱码久久久久 | 精品久久免费 | 波多野结衣亚洲 | 国产色秀视频 | 亚洲精品免费在线观看视频 | 欧洲一区二区 | 在线观看免费视频a | а√天堂www在线天堂小说 | 精品成人无码久久久久久 | 黄色片免费网站 | www.人人草 | 日本裸体视频 | 国产熟女一区二区 | 特大黑人巨交吊性xxxx视频 | 国产精品啪啪啪视频 | 国模视频一区二区 | 最新天堂在线视频 | 女生下面流水视频 | 国产精品一区二区三区在线播放 | 亚洲成年人专区 | 青青草.com | 午夜av导航 | 久久老司机精品视频 | 久久国产精品一区 | 欧美一区二三区 | 亚洲午夜精品一区二区三区他趣 | 青青草97国产精品免费观看 | 人妻熟妇又伦精品视频a | 国产午夜精品免费一区二区三区视频 | 99色热| 欧美z○zo重口另类黄 | 自拍偷拍亚洲综合 | 国产中文字幕第一页 | 亚洲天堂免费视频 | 日韩免费影视 | 8x8x永久免费视频 | 九九自拍偷拍 | 三年在线观看视频 | 欧洲精品久久一区二区 | 欧美三级自拍 | 国产偷人妻精品一区 |