11
22// 求两个数组的交集
33
4- let arr1 = [ 1 ]
5- let arr2 = [ 1 , 1 ]
4+ let arr1 = [ 1 , 1 , 4 ]
5+ let arr2 = [ 1 , 1 , 1 ]
66let arr = [ ] ;
77for ( let i = 0 ; i < arr1 . length ; i ++ ) {
88 for ( let j = 0 ; j < arr2 . length ; j ++ ) {
@@ -32,49 +32,52 @@ console.log(arr)
3232// console.log(result)
3333
3434
35- let mupltipy8 = ( num ) => num << 3
36- console . log ( mupltipy8 ( 7 ) )
35+ // let mupltipy8 = (num) => num << 3
36+ // console.log(mupltipy8(7))
37+
38+ // function bitAdd(m, n) {
39+ // while (m) {
40+ // [m, n] = [(m & n) << 1, m ^ n];
41+ // }
42+ // return n;
43+ // }
44+ // function multiply7(num) {
45+ // let sum = 0;
46+ // for (var i = 0; i < 7; i++) {
47+ // sum = bitAdd(sum, num);
48+ // }
49+ // return sum;
50+
51+ // }
52+ // console.log(multiply7(7)); //49
53+
54+
55+ // let str='aaadwiubcggkiwj';
56+ // const arry = str.match(/(\w)\1+/g); // 求出连续字符串
57+ // console.log(arry)
58+ // const maxLen = Math.max(...arry.map(s => s.length)); //求出最长长度
59+ // console.log(maxLen)
60+ // const result = arry.reduce((pre, curr) => {
61+ // if (curr.length === maxLen) {
62+ // pre[curr[0]] = curr.length;
63+ // }
64+ // return pre;
65+ // }, {});
66+ // console.log(result);
67+
68+
69+ // let arryn = ['1,3,2','1,89,37,4','1,4,2']
70+ // let m = arryn.toString().split(",").sort((a,b)=>{ return a-b}).map(Number)
71+ // console.log(m)
72+ // let n = [... new Set(m)] // 去重
73+ // console.log(n)
74+
75+
76+ // //parseInt() 函数解析一个字符串参数,并返回一个指定基数的整数 (数学系统的基础)。
77+ // //const intValue = parseInt(string[, radix]);
78+ // //string 要被解析的值。如果参数不是一个字符串,则将其转换为字符串(使用 ToString 抽象操作)。字符串开头的空白符将会被忽略。
79+ // //radix 一个介于2和36之间的整数(数学系统的基础),表示上述字符串的基数。默认为10。 返回值 返回一个整数或NaN
80+ // console.log(['1','2','3'].map(parseInt))
81+
3782
38- function bitAdd ( m , n ) {
39- while ( m ) {
40- [ m , n ] = [ ( m & n ) << 1 , m ^ n ] ;
41- }
42- return n ;
43- }
44- function multiply7 ( num ) {
45- let sum = 0 ;
46- for ( var i = 0 ; i < 7 ; i ++ ) {
47- sum = bitAdd ( sum , num ) ;
48- }
49- return sum ;
5083
51- }
52- console . log ( multiply7 ( 7 ) ) ; //49
53-
54-
55- let str = 'aaadwiubcggkiwj' ;
56- const arry = str . match ( / ( \w ) \1+ / g) ; // 求出连续字符串
57- console . log ( arry )
58- const maxLen = Math . max ( ...arry . map ( s => s . length ) ) ; //求出最长长度
59- console . log ( maxLen )
60- const result = arry . reduce ( ( pre , curr ) => {
61- if ( curr . length === maxLen ) {
62- pre [ curr [ 0 ] ] = curr . length ;
63- }
64- return pre ;
65- } , { } ) ;
66- console . log ( result ) ;
67-
68-
69- let arryn = [ '1,3,2' , '1,89,37,4' , '1,4,2' ]
70- let m = arryn . toString ( ) . split ( "," ) . sort ( ( a , b ) => { return a - b } ) . map ( Number )
71- console . log ( m )
72- let n = [ ... new Set ( m ) ] // 去重
73- console . log ( n )
74-
75-
76- //parseInt() 函数解析一个字符串参数,并返回一个指定基数的整数 (数学系统的基础)。
77- //const intValue = parseInt(string[, radix]);
78- //string 要被解析的值。如果参数不是一个字符串,则将其转换为字符串(使用 ToString 抽象操作)。字符串开头的空白符将会被忽略。
79- //radix 一个介于2和36之间的整数(数学系统的基础),表示上述字符串的基数。默认为10。 返回值 返回一个整数或NaN
80- console . log ( [ '1' , '2' , '3' ] . map ( parseInt ) )
0 commit comments