IT干货|让你轻松面对JavaScript | JavaScript算法-Starter kit toolbox

2018-09-27

JiangRen Mr

首先 

对于一个前端来说, 尤其是笔试面试的时候,算法方面其实考的不难,但是对于一个初学JavaScript或者对于不知道如何快速写算法的你来说,可能是很容易混淆的。 

所以, 小编这次带来了Tips / Tricks ,让你轻松面对!

8 Tips

在ECMAScript 6.0 (简称 ES6)是JavaScript 语言的下一代标准。

目的是使JavaScript语言可以用来编写复杂的大型应用程序,成为企业级开发语言。

 

PS: 以下所有代码都尊重 immutability principles (不变形原则), 从不改变 initial object (最初对象), 而是返回 a new object that have the desired properties (所需属性的新对象)。

 

1. Uniq Array

Create Set from our values, and then convert it back to an array ( if need be):

在转换回array之前, 记住Set自己也有一些有用的工具,例如size或者has

 

2. Update an array object by property

Update that has id: 3in the array.

当然, 这里的‘initial’ const 没有动。

 

3. Remove an object from array by property

Remove the object that has id === 3 from our array:

又一次, initial 没有改变。

 

4. Remove a key from an object

Denormalized(非规格化) assignment the other-way around:

5. Merge an array of objects together

这里,我们可以merge objects together, 或者 update them by their properties:

reduce 和 spread operators(扩展预算符)搭配的很好! 

6. Flatten

One-liner to flatten an array: 

7. From Pairs

One-liner: create object from pairs:

[key, value] denormalized assignment a lot  

8. Subtract two Sets

不是很经常用,但是还是很有帮助的。 

最后

希望大家都渐渐掌握这些小技巧, 慢慢的成为JavaScript大神,帮助大家在以后的求职的道路上又knock down一只拦路虎。

 

近期开课hot

Python零基础入门

start2025/02/12 03:14 (Sydney)

Web全栈班24期 NodeJS方向

start2024/12/08 11:30 (Sydney)

logo

Follow Us

linkedinfacebooktwitterinstagramweiboyoutubebilibilitiktokxigua

We Accept

/image/layout/pay-paypal.png/image/layout/pay-visa.png/image/layout/pay-master-card.png/image/layout/pay-stripe.png/image/layout/pay-alipay.png

地址

Level 10b, 144 Edward Street, Brisbane CBD(Headquarter)
Level 2, 171 La Trobe St, Melbourne VIC 3000
四川省成都市武侯区桂溪街道天府大道中段500号D5东方希望天祥广场B座45A13号
Business Hub, 155 Waymouth St, Adelaide SA 5000

Disclaimer

footer-disclaimerfooter-disclaimer

JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.

匠人学院网站上的所有内容,包括课程材料、徽标和匠人学院网站上提供的信息,均受澳大利亚政府知识产权法的保护。严禁未经授权使用、销售、分发、复制或修改。违规行为可能会导致法律诉讼。通过访问我们的网站,您同意尊重我们的知识产权。 JR Academy Pty Ltd 保留所有权利,包括专利、商标和版权。任何侵权行为都将受到法律追究。查看用户协议

© 2017-2024 JR Academy Pty Ltd. All rights reserved.

ABN 26621887572