Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //In this Kata, you will learn how to remove all empty items in an Array.
- //iterate... if
- function clean(arr) {
- arr.map( (elem, i, arr) => {
- if(elem === ' '){
- arr.splice(i, 1)
- }
- })
- return arr;
- }
- clean([1, 2,,,3, 4])
- // In JavaScript, empty items in arrays can be declared by [1, 2,,,3, 4] (Multiple commas without a value in that index)
- // The values that are not given a value are empty items, and usually add up with others to form <# empty items>; In the example, <2 empty items>
- // [1, 2, <2 empty items>, 3, 4] should be cleared such that it should be [1, 2, 3, 4]
- // Example:
- // Before: [1, 2, 3, <5 empty items>, 4, <1 empty item>, null, undefined];
- // After: [1, 2, 3, 4, null, undefined];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement