A few questions for quickly assessing candidate's Node.js skill level
- Write a function that simulates an asynchronous I/O function call. The function should be called
ping
. It should accept one argument calleddelay
that will determine how many seconds before the function will call back with a response (pong
). If no argument is provided, it should call back immediately. If the argument is greater than 3, it should call back with an error.
function ping(delay, callback) {
// if delay is not provided, it should default to 0
if (typeof delay === 'function') {
callback = delay;
delay = 0;