Skip to main content

Alibaba Beijing Interview Round 1

· One min read
Xiaohai Huang
  1. What are JS primitive data types?
    1. What's the use of Symbol?
    2. Have you used BigInt?
  2. Tell me about prototype chain.
  3. How do you implement a virtualized list? solution
  4. Map vs plain object? MDN solution
  5. flexbox
  6. How to narrow a variable's type in typescript?

Programming

Curry

Implement the following function

// add(5, 2)  7
// add(5)(2) 7
function curry(func) {
return function curried(...args) {
if (args.length >= func.length) {
return Reflect.apply(func, undefined, args);
} else if (args.length < func.length) {
return (...a) => curried(...args, ...a);
}
};
}

function add(a, b) {
return a + b;
}
const curriedAdd = curry(add);
console.log(curriedAdd(2)(5)); // 7
console.log(curriedAdd(2, 5)); // 7

Sort

Sort an array, even number on the left (in descending order), odd number on the right (in ascending order) and 0 in the middle.

// [1,4,5,2,7,0]   =>   [4,2,0,1,5,7]