10 Javascript Exercises with Arrays

Andrei Borisov
6 min readApr 29, 2020

Basically, this article could be useful for junior and middle Javascript software engineers. I prepared ten exercises with arrays, which I hope will help you to improve your coding skills.

Each task provided has an explanation, expected result, and solution. I do not affirm my solutions are the best ways to solve each of the exercises, but I believe they could help you to find some new ideas if you stuck.

Also, I would like to mention that I won’t handle all the error cases, like passing undefined, null, or wrong data types. I provide a basic solution, not writing a library for production.

You can start in your repository or clone mine. In that repository, you can find a full list of exercises and solutions. Also, you can easily check your solutions with pre-created tests. Link: https://github.com/andrewborisov/javascript-practice.

1. Fill. Write a function that creates a new array with given values

/** 
* Task description: Write a method that creates a new array with given values
* Expected Result: (3, 'a') => ['a', 'a', 'a']
* Task Complexity: 1 of 5
* @param {number} arraySize - size of array
* @param {?} value - value to fill
* @returns {Array}
*/
const fill = (arraySize, value) => {
throw new Error('Put your solution here');
}

--

--