Back to Type Challenges

README.Zh CN

questions/09989-medium-tong-ji-shu-zu-zhong-de-yuan-su-ge-shu/README.zh-CN.md

latest1.6 KB
Original Source
<!--info-header-start--><h1>统计数组中的元素个数 </h1><blockquote><p>by 凤之兮原 <a href="https://github.com/kongmingLatern" target="_blank">@kongmingLatern</a></p></blockquote><p><a href="https://tsch.js.org/9989/play/zh-CN" target="_blank"></a> &nbsp;&nbsp;&nbsp;<a href="./README.md" target="_blank"></a> </p><!--info-header-end-->

通过实现一个CountElementNumberToObject方法,统计数组中相同元素的个数

ts
type Simple1 = CountElementNumberToObject<[]> // return {}
type Simple2 = CountElementNumberToObject<[1,2,3,4,5]> 
/*
 return {
  1: 1,
  2: 1,
  3: 1,
  4: 1,
  5: 1
}
*/
type Simple3 = CountElementNumberToObject<[1,2,3,4,5,[1,2,3]]> 
/*
 return {
  1: 2,
  2: 2,
  3: 2,
  4: 1,
  5: 1
}
*/
<!--info-footer-start-->

<a href="../../README.zh-CN.md" target="_blank"></a> <a href="https://tsch.js.org/9989/answer/zh-CN" target="_blank"></a> <a href="https://tsch.js.org/9989/solutions" target="_blank"></a> <!--info-footer-end-->