zoukankan      html  css  js  c++  java
  • 应聘前端开发的一次笔试题目(某外资公司)

    虽然网络上也有原题,为做些许保密,以下使用相同原理的例子。

    1. Write a regular expression to extract an ID from a text. The ID consists of 8 hex numbers, and follows the string "postid=". (The extracted value should not contain the string "postid=") For example, below text, should extract "12106616“:

      https://i.cnblogs.com/EditPosts.aspx?postid=12106616&postAddress=127%200%200%201 GET

    Suggested answer 

    /* /(?<=?postid=)d{8}/ */
    'https://i.cnblogs.com/EditPosts.aspx?postid=12106616&postAddress=127%200%200%201 GET'.match(/(?<=?postid=)d{8}/)[0];

      Transformation: extract the string between "postid=" and "&postAddress"

    /* /(?<=postid=).*(?=&postAddress)/ */
    'https://i.cnblogs.com/EditPosts.aspx?postid=12106616&postAddress=127%200%200%201 GET'.match(/(?<=postid=).*(?=&postAddress)/)[0];

       2. What will the code below output to the console and why?

     1 var newObj= {
     2     foo: "bar",
     3     catchThis: function() {
     4         var self = this;
     5         console.log("outer func:  this.foo = " + this.foo);
     6         console.log("outer func:  self.foo = " + self.foo);
     7         (function() {
     8             console.log("inner func:  this.foo = " + this.foo);
     9             console.log("inner func:  self.foo = " + self.foo);
    10         }());
    11     }
    12 };
    13 newObj.catchThis();

     Suggested Answer

    outer func:  this.foo = bar
    outer func:  self.foo = bar
    inner func:  this.foo = undefined
    inner func:  self.foo = bar

      Explanation: In the outer function, both this and self refer to newObj and therefore both can properly reference and access foo.

    In the inner function, though, this no longer refers to newObj. As a result, this.foo is undefined in the inner function, whereas the reference to the local variable self remains in scope and is accessible there.

     

    3. What will the code below output to the console and why? 

    1 Promise.resolve(1)  
    2   .then((x) => x / 2)
    3   .then((x) => { throw new Error('My Error') })
    4   .catch(() => 5)
    5   .then((x) => x * 2)
    6   .then((x) => console.log(x))
    7   .catch(console.error)

    Suggested Answer

    The short answer is 10

     

    4. Programming: Implement a function by using JavaScript, to count each letter's occurrence number in a text. (assume that all the words split using space; G2 is a library based on visual encoding for manipulating the grammar of graphics.).

    Suggested Answer

    function count (text) {
        var arr = text.split("")// result用作保存A~Z, a-z的对象, 形如 {A: 1, B: 2, a: 1, b: 3}
        let result = {}
      /* ascii code table: A-65, z-90, a-97, z-122
        String.fromCharCode(number), String.charCodeAt(0)
      */
    for (let i = 65; i <= 122; i++) { result[String.fromCharCode(i)] = 0 // 计算每个字母(区分大小写)的出现次数 arr.forEach(element => { if (element === String.fromCharCode(i)) result[String.fromCharCode(i)]++ }) } let obj = {} // 筛选出现次数大于0的字母 for (let key in result) { if (result[key] !== 0) { obj = Object.assign(obj, { [key]: result[key] }) } } console.log(obj) }

    5. Programming: Use H5, CSS and JS to write a page to display 6 images with following requirements. (Requirement: omit)

    Suggested Answer: omit

    Reference

    1. https://www.toptal.com/javascript/interview-questions 37 Essential JavaScript Interview Questions
    2. http://quizbucket.org/nodejs-interview-questions?page=5   NodeJS interview questions
    3. https://juejin.im/post/5d5b68b8f265da03f33354cc 关于 ES6 中 Promise 的面试题

       

    附英文自我介绍(请挑错):

    My name is JumperMan, I am from Guangdong Province, graduated in 20xx with a bechalor degree.
    Since becoming a computer engineer, I have worked for almost 6 year.
    At the begining of the 2 years, I worked in a shoes industry company, coding and developing relevant procedure with ASP.NET of c# language and the database of SQL server in the platform of VS2010.
    In the following 3 years, I worked in a software company of the textile industry, then turing into the front end engineer with AngularJS, AvalonJS and Node. The former company business serves for the traditional erp(enterprise resource planning) which we focus on some procudures such as order supervisor, finace, warehouse, statistics and so on.
    In the lastest year, I worked in a data analysis company of the enviromental sanitation. I become a frond end developer, specialising the Web development and mobile terminal development within the front-end framework of Vue, the UI component library of ElementUI, the visual statistical graphics of AntV(known as Alipay's Ant Financial Group).

  • 相关阅读:
    浅谈块元素绝对定位的margin属性
    因浏览器而异的空白节点(js清除空白节点)
    区分中英文字符的两种方法
    js中 visibility和display的区别 js中 visibility和display的区别
    观察者模式
    单例模式
    mongodb
    javascript的加载、解析、执行对浏览器渲染的影响
    EM算法原理
    YARN
  • 原文地址:https://www.cnblogs.com/JumperMan/p/12106616.html
Copyright © 2011-2022 走看看