In this lesson we cover all the details of how to sort a list of items using TypeScript. We also present a few tricks to make your sort logic more readable and maintainable using TypeScript.

.sort() function is a mutation function, it means it will mutate the original array by default.

To prevent mutation:

const arr: ReadonlyArray<string> = ['foo', 'bar'];
const copy = arr.slice().sort();

Here we use 'ReadonlyArray<T>' to tell Typescript, this is a readonly array of string type. So IDE will tell you if you try to mutate the array.

Second, to avoid mutation, we use 'arr.slice()' to copy the original array, then do the sorting.

最新文章

  1. Sql Server系列:数据库对象
  2. Retroactive priority queues
  3. css hover对其包含的元素进行样式设置
  4. ArcGIS 10.1 中的style和serverstyle及制作方法
  5. HTML5基础-Mark标签高亮显示文本
  6. 【心得&amp;&amp;体会】
  7. JS初学之-效果没出来怎么办?-alert函数测试
  8. 关于sql语句in的使用注意规则
  9. uva live 6190 Beautiful Spacing (二分法+dp试 基于优化的独特性质)
  10. iOS跳转系统设置界面
  11. Servlet实现文件上传(深度)(二)
  12. 使用python操作mysql
  13. Mac安装Elasticsearch时提示:No Java runtime present, requesting install.
  14. 野路子码农系列(3)plotly可视化的简单套路
  15. python全栈开发day21-2 几个装饰器总结
  16. 通过 rufus 创建启动U盘,安装 VMWare Esxi
  17. KDiff
  18. iOS 静态库生成(引用第三方SDK、开源库、资源包)
  19. graphviz 程序生成多种类型图表详解
  20. VC6IDE环境宏辅助添加移除注释

热门文章

  1. Spider_selenium
  2. Google 免费公共 DNS 服务器
  3. Flask项目之手机端租房网站的实战开发(十一)
  4. Excel数据比对-批量数据比对
  5. CODEVS——T 1993 草地排水 USACO
  6. Excel 下拉菜单制作
  7. Android 关于java.util.NoSuchElementException错误
  8. python3 turtle 画围棋棋盘
  9. loadrunner--log的使用总结
  10. Loadrunner--web_find和web_reg_find的用法和区别