1) Write a function that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] → [1,2,3,4]. If the language you’re using has a function to flatten arrays, you should pretend it doesn’t exist.

2) Build a simple file uploader which can be used by other applications as a plugin or module. The uploader should have following features:

  • Configurable upload URL and param name.
  • Show live preview on the browser if the file is an image.
  • Customize file extensions to be allowed. For example: [‘image/png’, ‘image/jpg’]
  • Ability to send extra data when uploading the file. For example Sending user_id with each file.

Please note:

When writing code do not worry about the browser inconsistencies or design (you can target a single browser you feel comfortable with). Make sure the code is written using pure Javascript and do not make use of any 3rd party libraries.

Also, write the code the way you will write it in production. Some guidelines are:

  1. Have a proper test suite covering edge cases.
  2. Try avoiding using random names for variables/functions. The naming of methods should be relevant to the code domain.