Skip to content

Instantly share code, notes, and snippets.

@malash
Last active January 11, 2018 03:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malash/fc9dc0689feec16f7de95c36ba986db2 to your computer and use it in GitHub Desktop.
Save malash/fc9dc0689feec16f7de95c36ba986db2 to your computer and use it in GitHub Desktop.
常用面试JavaScript题目
function Test() {
  this.run = function() {
    console.log('run', this);
    setTimeout(this.run, 1000);
  }
}
const t = new Test();
t.run();

for (var i = 0; i < 10; i++) {
  setTimeout(function () {
    console.log(i);
  }, 1000);
}

F.of(1)
  .add(2)
  .mul(3)
  .map(x => console.log(x))

new Promise((resolve, reject) => {
  console.log('A');
  resolve();
  console.log('B');
})
  .then(() => {
    console.log('C');
  });
console.log('D');
setTimeout(() => console.log('E'), 0);
process.nextTick(() => console.log('F'));

const a = [1, 3, 5];
const b = [2, 4, 6];
const c = f(a, b); // [1, 2, 3, 4, 5, 6];

console.log(['1', '2', '3'].map(parseInt));

console.log(f(10)); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

function isOdd(num) {
  return num % 2 == 1;
}
function isEven(num) {
  return num % 2 == 0;
}
function isSane(num) {
  return isEven(num) || isOdd(num);
}
var values = [7, 4, '13', -9, Infinity];
values.map(isSane);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment