实战系列-速魔科技

141 阅读1分钟

速魔科技

面试时间

2024-03-16 AM 9:30

背景介绍

深圳一家 22~99人公司分公司,主公司在龙华,在南山准备扩展分部,主营硬件,需求开发桌面端调试硬件配置,招前端工程师。

薪资范围

20~30k x 14薪

面试流程:

一轮笔试 + 一轮面试(hr + 技术)

笔试

1.随机颜色值

function randomColor (){     
  return  '#' +     
    (function(color){     
    return (color +=  '0123456789abcdef'[Math.floor(Math.random()*16)])     
      && (color.length == 6) ?  color : arguments.callee(color);     
  })('');     
}
// console.log(randomColor()) => #92c66

2.数组求和

function sum(arr) {
    return arr.reduce(function(prev, curr, index, arr){
        return prev + curr;
    });
}
// console.log(sum([ 1, 2, 3, 4 ])) => 10

3.分页

function pagination(arr, pageSize, currentPage) {
  const startNum = (currentPage - 1) * pageSize;
  const endNum = currentPage * pageSize;
  return arr.splice(startNum, endNum);
}
// console.log(pagination([ 1, 2, 3, 4, 5, 6, 7, 8, 9 ], 5, 2)) => [6, 7, 8, 9]
  1. 判断一个点是否存在圆内
function isPointOnCircle(point, circle) {
   const distanceSquare = (point.x -  circle.center.x) * (point.x -  circle.center.x) + 
   (point.y -  circle.center.y) * (point.y -  circle.center.y)
   return distanceSquare < circle.radius * circle.radius
}
// 使用示例
console.log(isPointOnCircle({ x: 5, y: 5 }, { center: { x: 0, y: 0 }, radius: 5 })); // false

5.创建、遍历二叉树

// 创建二叉树
class TreeNode {
    constructor(value) {
        this.value = value;
        this.left = null;
        this.right = null;
    }
}

function createBinaryTree() {
    const node1 = new TreeNode(1);
    const node2 = new TreeNode(2);
    const node3 = new TreeNode(3);
    const node4 = new TreeNode(4);
    const node5 = new TreeNode(5);
    const node6 = new TreeNode(6);
    
    node1.left = node2;
    node1.right = node3;
    node2.left = node4;
    node2.right = node5;
    node3.left = node6;
    
    return node1;
}

function preorderTraversal(root) {
    if (root === null) return;
    console.log(root.value); // 访问根节点
    preorderTraversal(root.left); // 遍历左子树
    preorderTraversal(root.right); // 遍历右子树
}

const root = createBinaryTree();

console.log(root)
preorderTraversal(root);