当前位置:网站首页>JS merge multiple string arrays to maintain the original order and remove duplicates
JS merge multiple string arrays to maintain the original order and remove duplicates
2022-06-13 02:52:00 【Programming Bruce Lee】
Realization effect
Merge any string array , And keep the original order of strings for merging and de duplication , The effect is shown in the figure :
The implementation code is as follows
First, simply implement the merging between two string arrays , recycling js The implementation of recursive call with variable parameters of n A combination of string arrays
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Dragon brother </title>
</head>
<body>
<script type="text/javascript"> /** * Merge in order n Array of strings and remove duplicates * @param {...any} strArrys // Array of multiple character strings */ function mergeStrArrays(...strArrys) {
if (!strArrys) {
return []; } // Recursive export if (strArrys.length < 2) {
return strArrys[0] ? strArrys[0] : []; } // Recursively call return mergeStrArrays(mergeStrArray(strArrys.pop(), strArrys.pop()), ...strArrys); } /** * Merge two string arrays in order and remove duplicates * @param {Array} strArry1 Array of strings * @param {Array} strArry2 Array of strings * @returns */ function mergeStrArray(strArry1, strArry2) {
if (strArry2.length > strArry1.length) {
// Guarantee strArry1 Than strArry2 Long let strT = strArry2; strArry2 = strArry1; strArry1 = strT; } for (let i = 0; i < strArry1.length; i++) {
if (strArry2[i] === undefined) {
break; } // If the corresponding position str1 Elements and str2 Elements are different and str1 There is no such element in the array , Add... At this location str2 Elements if (strArry1[i] !== strArry2[i]) {
let j = 0; for (j; j < strArry1.length; j++) {
if (strArry1[j] === strArry2[i]) {
break; } } if (j >= strArry1.length) {
strArry1.splice(i, 0, strArry2[i]); } } } return strArry1; } let str1 = ["aaa", "bbb", "ccc", "ddd", "eee"] let str2 = ["bbb", "ccc", "eee", "ffff"] let str3 = ["bbb", "ccc", "mmm", "ggg"] console.log(" The three string arrays are :"); console.log(str1); console.log(str2); console.log(str3); console.log(" After the merger :"); console.log(mergeStrArrays(str1, str2, str3)); </script>
</body>
</html>
边栏推荐
- Svg filter effect use
- Change tax for 2
- Detailed explanation of UCI datasets and their data processing (with 148 datasets and processing codes attached)
- Opencv 10 brightness contrast adjustment
- [data analysis and visualization] key points of data drawing 5- the problem of error line
- HEAP[xxx.exe]: Invalid address specified to RtlValidateHeap( 0xxxxxx, 0x000xx)
- Linked list: orderly circular linked list
- AAR packaging and confusion
- 数仓笔记|针对客户维度建模需要关注的5个因素
- Digital IC Design -- FIFO design
猜你喜欢

数仓笔记|针对客户维度建模需要关注的5个因素

For loop instead of while loop - for loop instead of while loop
![[reading papers] visual convolution zfnet](/img/01/4181f19b2d24b842488522c2001970.jpg)
[reading papers] visual convolution zfnet

OneNote User Guide (1)
![[reading papers] deepface: closing the gap to human level performance in face verification. Deep learning starts with the face](/img/e4/a25716ae7aa8bdea64eb9314ca2cc7.jpg)
[reading papers] deepface: closing the gap to human level performance in face verification. Deep learning starts with the face

02 optimize the default structure of wechat developer tools
![[reading papers] dcgan, the combination of generating countermeasure network and deep convolution](/img/31/8c225627177169f1a3d6c48fd7e97e.jpg)
[reading papers] dcgan, the combination of generating countermeasure network and deep convolution

Introduction and download of common data sets for in-depth learning (with network disk link)

Code d'initialisation de l'arbre binaire

Pycharm and Anaconda ultra detailed installation and configuration tutorial
随机推荐
Hash table: whether alien languages are sorted
FFmpeg原理
[common tools] pyautogui tutorial
OpenCVSharpSample04WinForms
The weight of the input and textarea components of the applet is higher than that of the fixed Z-index
Use of OpenCV 11 kmeans clustering
Special topic I of mathematical physics of the sprint strong foundation program
Prometheus安装并注册服务
Entity framework extends the actual combat, small project reconfiguration, no trouble
Matlab: obtain the figure edge contour and divide the figure n equally
Svg filter effect use
OneNote使用指南(一)
String: number of substring palindromes
A wechat app for shopping
Detailed installation tutorial of MATLAB r2019 B-mode ultrasound (complete installation files are attached)
[data analysis and visualization] key points of data drawing 6- too many data groups
Stm32f4 DMA Da sine wave generator keil5 Hal library cubemx
vant实现移动端的适配
Linked list: palindrome linked list
Data processing in detailed machine learning (II) -- Feature Normalization