Title: 腾讯:数组扁平化、去重、排序 · Issue #5 · sisterAn/JavaScript-Algorithms · GitHub
Open Graph Title: 腾讯:数组扁平化、去重、排序 · Issue #5 · sisterAn/JavaScript-Algorithms
X Title: 腾讯:数组扁平化、去重、排序 · Issue #5 · sisterAn/JavaScript-Algorithms
Description: 关于 Array 的属性、方法这里不再做介绍,详看 MDN Array 。 面试题: 已知如下数组:var arr = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10]; 编写一个程序将数组扁平化去并除其中重复部分数据,最终得到一个升序且不重复的数组 答案: // 扁平化 const flattenDeep = (array) => array.flat(Infinity)...
Open Graph Description: 关于 Array 的属性、方法这里不再做介绍,详看 MDN Array 。 面试题: 已知如下数组:var arr = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10]; 编写一个程序将数组扁平化去并除其中重复部分数据,最终得到一个升序且不重复的数组 答案: // 扁平化 const flatt...
X Description: 关于 Array 的属性、方法这里不再做介绍,详看 MDN Array 。 面试题: 已知如下数组:var arr = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10]; 编写一个程序将数组扁平化去并除其中重复部分数据,最终得到一个升序且不重复的数组 答案: // 扁平化 const flatt...
Opengraph URL: https://github.com/sisterAn/JavaScript-Algorithms/issues/5
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"腾讯:数组扁平化、去重、排序","articleBody":"关于 `Array` 的属性、方法这里不再做介绍,详看 [MDN Array](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array) 。\r\n\r\n面试题:\r\n\r\n\u003e 已知如下数组:var arr = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10];\r\n\u003e\r\n\u003e 编写一个程序将数组扁平化去并除其中重复部分数据,最终得到一个升序且不重复的数组\r\n\r\n答案:\r\n\r\n```js\r\n// 扁平化\r\nconst flattenDeep = (array) =\u003e array.flat(Infinity)\r\n\r\n// 去重\r\nconst unique = (array) =\u003e Array.from(new Set(array))\r\n\r\n// 排序\r\nconst sort = (array) =\u003e array.sort((a, b) =\u003e a-b)\r\n\r\n// 函数组合\r\nconst compose = (...fns) =\u003e (initValue) =\u003e fns.reduceRight((y, fn) =\u003e fn(y), initValue)\r\n\r\n// 组合后函数\r\nconst flatten_unique_sort = compose( sort, unique, flattenDeep)\r\n\r\n// 测试\r\nvar arr = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10]\r\nconsole.log(flatten_unique_sort(arr))\r\n// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\r\n```\r\n\r\n可结合 [携程\u0026蘑菇街\u0026bilibili:手写数组去重、扁平化函数](https://github.com/sisterAn/JavaScript-Algorithms/issues/30) 查看","author":{"url":"https://github.com/sisterAn","@type":"Person","name":"sisterAn"},"datePublished":"2020-04-03T04:03:05.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":24},"url":"https://github.com/5/JavaScript-Algorithms/issues/5"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7e0cc789-f871-9dfc-e5ec-742e39fa399f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B496:311995:FB09C:145C30:696AD5BB |
| html-safe-nonce | fe22019cef87caebc026c69fcc9ac6a42be7b48c276d504819a80e713627d817 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNDk2OjMxMTk5NTpGQjA5QzoxNDVDMzA6Njk2QUQ1QkIiLCJ2aXNpdG9yX2lkIjoiMjU2MTg2NzE5MjYxMjg2OTU2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8a1beaf4e507b042c2f9c0ec762bf905ef7c69764b5ee577f4815e93cfca6514 |
| hovercard-subject-tag | issue:593060551 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/sisterAn/JavaScript-Algorithms/5/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7e2469730ce303df88e421c5e1611be62cda383af3dbb6aac55a1219a9e92cc3/sisterAn/JavaScript-Algorithms/issues/5 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7e2469730ce303df88e421c5e1611be62cda383af3dbb6aac55a1219a9e92cc3/sisterAn/JavaScript-Algorithms/issues/5 |
| og:image:alt | 关于 Array 的属性、方法这里不再做介绍,详看 MDN Array 。 面试题: 已知如下数组:var arr = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10]; 编写一个程序将数组扁平化去并除其中重复部分数据,最终得到一个升序且不重复的数组 答案: // 扁平化 const flatt... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sisterAn |
| hostname | github.com |
| expected-hostname | github.com |
| None | c785f4ce187e9e7331257791b36ddee01625bb8e292a9b4fe2c16d4c006abf5d |
| turbo-cache-control | no-preview |
| go-import | github.com/sisterAn/JavaScript-Algorithms git https://github.com/sisterAn/JavaScript-Algorithms.git |
| octolytics-dimension-user_id | 19721451 |
| octolytics-dimension-user_login | sisterAn |
| octolytics-dimension-repository_id | 252061924 |
| octolytics-dimension-repository_nwo | sisterAn/JavaScript-Algorithms |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 252061924 |
| octolytics-dimension-repository_network_root_nwo | sisterAn/JavaScript-Algorithms |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c718a376fcf780eb22089171adb84a543f660bf7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width