1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+
4+ < head >
5+ < meta charset ="UTF-8 ">
6+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
7+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
8+ < link rel ="stylesheet " href ="./assets/global.css ">
9+
10+ < style >
11+ textarea {
12+ min-width : 300px ;
13+ }
14+ </ style >
15+ </ head >
16+
17+ < body >
18+ < div class ="group-title "> 数组A</ div >
19+ < textarea id ="arrayA " rows ="10 "> </ textarea >
20+ < div class ="group-title "> 数组B</ div >
21+ < textarea id ="arrayB " rows ="10 "> </ textarea >
22+ < div >
23+ < button class ="contrast-btn "> 对比</ button >
24+ </ div >
25+ < div class ="group-title "> 交集C</ div >
26+ < textarea id ="arrayC " rows ="10 "> </ textarea >
27+ < div class ="group-title "> 补集D (A补C)</ div >
28+ < textarea id ="arrayD " rows ="10 "> </ textarea >
29+ < div class ="group-title "> 补集E (B补C)</ div >
30+ < textarea id ="arrayE " rows ="10 "> </ textarea >
31+ < script type ="module ">
32+ import { Maths } from "https://gcore.jsdelivr.net/npm/@3r/tool/lib/maths.js" ;
33+ document . querySelector ( '.contrast-btn' ) . addEventListener ( 'click' , ( ) => {
34+ /** @type {string } */
35+ let arrayAOrigin = document . querySelector ( '#arrayA' ) . value
36+ /** @type {string } */
37+ let arrayBOrigin = document . querySelector ( '#arrayB' ) . value
38+
39+ let arrayA = arrayAOrigin . split ( / \n / ) . map ( item => item . trim ( ) )
40+ let arrayB = arrayBOrigin . split ( / \n / ) . map ( item => item . trim ( ) )
41+
42+ let arrayC = Maths . intersection ( arrayA , arrayB ) ;
43+ let arrayD = Maths . complementarySet ( arrayC , arrayA ) ;
44+ let arrayE = Maths . complementarySet ( arrayC , arrayB ) ;
45+
46+ arrayD = Maths . removeRepeat ( arrayD ) ;
47+ arrayE = Maths . removeRepeat ( arrayE ) ;
48+
49+ document . querySelector ( '#arrayC' ) . textContent = arrayC . join ( '\n' ) ;
50+ document . querySelector ( '#arrayD' ) . textContent = arrayD . join ( '\n' ) ;
51+ document . querySelector ( '#arrayE' ) . textContent = arrayE . join ( '\n' ) ;
52+
53+ console . log ( arrayD , arrayE ) ;
54+ } )
55+
56+ </ script >
57+ </ body >
58+
59+ </ html >
0 commit comments