Last active
June 14, 2017 22:10
-
-
Save bluepnume/d8692813ecb981cbcf3a417975202eb4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Write a `until(condition, finalCallback)` function that calls the `condition` function until the result is truthy, then calls the final callback | |
function waitUntilUserLoggedIn() { | |
until(function(callback) { | |
ajax('/api/user', function(err, user) { | |
if (err) { | |
callback(err); | |
} else { | |
callback(null, user.is_logged_in ? true : false) | |
} | |
}); | |
}, function(err, result) { | |
console.log('user is logged in!'); | |
}); | |
} | |
// 2. Write a function that tests if a function is alphanumeric [0-9a-zA-Z] *without* using a regex, and returns true/false | |
// 3. Write a regex which matches the following lines: | |
var foo = 'bar'; | |
let xy_z = '123'; | |
const ab123 = "hello world"; | |
// 4. Write a "once" function | |
function sayHello(person) { | |
console.log('hello', person) | |
} | |
let sayHelloOnce = once(sayHello); | |
sayHelloOnce('jill'); | |
sayHelloOnce('jill'); | |
sayHelloOnce('jill'); | |
// Should only log 'hello jill' a single time | |
// 5. You have an ajax function which takes a callback: | |
ajax('/foobar', function(err, result) { | |
if (err) { | |
// do something | |
} else { | |
// do something | |
} | |
}); | |
// Using ajax(), write a promiseAjax() function which calls ajax() and turns it into a promise, so I can do: | |
ajaxPromise('/foobar').then(function(result) { | |
// do something | |
}).catch(function(err) { | |
// do something | |
}); | |
// 6. Write a function which finds the sum of all the numbers in a nested array, like [1, 2, 3, [ 5, 2, 4, [ 3 ], 4, [ 6, 4, 5, [ 1, 2 ] ] ] ] | |
// 7. Write a function to find all the prime numbers between 1 and 1000 | |
// 8. Write a form with a text field and a button, and write some javascript to only allow the form to submit if the text field has a word with a number of letters divisible by 3 | |
// 9. Write a text box which takes what you type and puts it onto the page as you type | |
// 10. Write a React component which does the same as #9 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment