1. 程式人生 > 其它 >2021大場面試題(十)

2021大場面試題(十)

1.已知資料格式,實現一個函式fn找出鏈條轉給你所有的父級 id

const value = '112';
const fn = (value) => {}
fn(value); //輸出 [1, 11, 112]
const data = [{
    id: '1',
    name: 'test1',
    children: [{
            id: '11',
            name: 'test11',
            children: [{
                    id: '111',
                    name: 'test111',
                },
                {
                    id: '112',
                    name: 'test112',
                }
            ]
        },
        {
            id: '12',
            name: 'test12',
            children: [{
                    id: '121',
                    name: 'test121',
                },
                {
                    id: '122',
                    name: 'test122',
                }
            ]
        }
    ]
}]

2.給定兩個大小為m 和 n 的有序陣列nums1 和 nums2。請找出這兩個有序陣列的中位數。要求演算法的事件複雜度為O(log(m+n))。

示例1:

nums1 = [1, 3], nums2 = [2]; 中位數是 2.0

示例2:

nums1 = [1, 2], nums2 = [3, 4]; 中位數是(2+3)/ 2 = 2.5;

3.vue 在 v-for時每項元素繫結事件需要事件代理嗎?為什麼

4.模擬實現一個深拷貝,並考慮物件相互引發作用以及Symbol拷貝的情況

5.介紹下前端加密的常見場景和方法

6. React 和 Vue 的diff 時間複雜度從O(n^3) 優化 到 O(n),那麼O(n^3) 和 O(n) 是如何計算出來的?

7.寫出如下程式碼的列印結果

function changeObjProperty(o) {
    o.siteUrl = 'http://www.baidu.com';
    o = new Object();
    o.siteUrl = 'http://www.google.com'
}

let webSite = new Object();
changeObjProperty(webSite);
console.log(webSite.siteUrl);

8.程式設計演算法題

用JavaScript 寫一個函式, 輸入 int 型返回整數逆序後的字串。如:輸入整形1234, 返回逆序字串 ‘4321’。

要求:必須使用遞迴函式呼叫,不能用全域性變數,輸入函式必須只有一個引數傳入,必須返回字串。

9. 請寫出如下程式碼的列印結果

function Foo() {
  Foo.a = function() {
    console.log(1);
  }
  this.a = function() {
    console.log(2);
  }
}

Foo.prototype.a = function() {
  console.log(3)
}

Foo.a = function() {
  console.log(4)
}

Foo.a();
let obj = new Foo();
obj.a();
Foo.a();