Write a function that returns the elements in the array that have a distance < 1000
functionf1(array) {let filterDistances = []for (let i =0; i <distances.length; i ++) {if (distances[i].distance <1000) {filterDistances.push(distances[i]) } }return filteredDistances;}functionf2(array) {returndistances.filter(item =>item.distance <1000);}
Write a function that returns the total distance of all the elements in the array.
functionf1(array) {let total =0for (let i =0; i <distances.length; i++) { total += distances[i].distance; }return total;}functionf2(array) {returndistances.reduce((acc, item) => acc+item.distance,0);}
Write a function that returns the total distance (in miles) of all of the items that are < 1000 km
functionf1(array) {let total =0for(let i =0; i <distances.length; i++){if(distances[i].distance <1000){ total += distances[i].distance *0.621371; } }return total;}functionf2(array) {return distances.filter(item =>item.distance <1000).map(item =>item.distance *0.621371).reduce((prev, distance) => prev + distance,0);}
Write a function capitalize that takes a string and uses .map to return the same string in all caps.
Now write a new function called swapCase that takes a string of words and uses .map and your newly written capitalize() function to return a string where every other word is in all caps.