Coder Social home page Coder Social logo

s1ngs1ng / freecodecampproject Goto Github PK

View Code? Open in Web Editor NEW
10.0 10.0 0.0 349 KB

freeCodeCamp Project: Calculator ⚙️ and Local Weather app 🌨

Home Page: https://singsing.io/freeCodeCampProject

HTML 10.79% JavaScript 40.26% CSS 17.19% TypeScript 31.77%

freecodecampproject's People

Contributors

s1ngs1ng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

freecodecampproject's Issues

代码过于冗余

return transformFunc(temp);

关于数组的排序你写了3个函数: transformFunc、_isLargerThan、_comparator 来实现,代码互相缠绕,实在过于冗余。
其实只需一行即可:

let sortedValue = cardList.map(card => card.value).sort((a,b)=>b-a);

此处的 do while 很精妙

} while (this.cache[card.suit].includes(card.value));

用 while 来判断如果生成的 card 是重复的,则循环生成新的 card,直到新的 card 为唯一。
此处我的思路是:
首先生成52张牌。
然后在52张中随机取一张,在51张中随机取一张,以此类推,取5张为玩家手牌。
再次调用时,从47张中随机取一张,取满5张为电脑手牌。
利用数组的 splice 特性,无需手动去掉重复卡牌。
利用数组的 length 属性,无需手动计算具体的位置。

代码不够抽象

sort 是一个抽象程度很高的数组方法,在 v8 中根据ECMAScript 中定义的 sort 方法有了具体实现。
开发者只需关注参数的顺序即可,例如:

[1,2,5,11,9].sort((a,b)=>a-b) // [1,2,5,9,11]
[1,2,5,11,9].sort((a,b)=>b-a) // [11,9,5,2,1]

此处的修改可以参考我的代码哦,^_^

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.