Below are details of how to apply for this web-dev job.
In a system, files often need to be fetched or processed asynchronously. Given a prepare_file function, which takes a path and a callback, write a process_files function which takes an array of paths, applies prepare_file to each element, and returns the array of results to a provided callback. The result array should be in the same order as the input array.
Below is a function stub for prepare_file, which simulates an asynchronous task for processing the provided path, and returning the result. (The actual prepare_file function implementation should be considered a black box when implementing process_files.)
function prepare_file(path, callback) { setTimeout(function () { callback(path + "_found"); }, 1000*Math.random()); };
Example use of prepare_file:
prepare_file('a', function (path) { // path should equal 'a_found' });
Example use of process_files:
process_files(['a', 'b', 'c'], function (paths) { // paths should equal ['a_found', 'b_found', 'c_found'] });
Answers may be in JavaScript or CoffeeScript and should assume the presence of a global prepare_file function (you can use the prepare_file stub above for testing your solution). You shouldn’t use any other libraries.
What next?
Send your answer to the task by email to jobs at allyearbooks.co.uk along with a cover letter, CV and/or anything that might impress us.
You can also call Jake on 07791 068 122 to discuss your application.