Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const array1 = [1, 0, 2, 3, 4];
- const array2 = [3, 5, 6, 7, 8, 13];
- const getMaxLengthFromArrays = (firstArray, secondArray) => Math.max(firstArray.length, secondArray.length);
- const isNumber = value => isNaN(value) ? 0 : value;
- const getSumFromTwoArrays = (firstArray, secondArray) => {
- const arrayFromTotalLength = Array.from({ length: getMaxLengthFromArrays(firstArray, secondArray) });
- return arrayFromTotalLength.reduce((acc, _, idx) => {
- return [...acc, isNumber(firstArray[idx]) + isNumber(secondArray[idx])]
- }, []);
- }
- console.log(computeSumFromTwoArrays(array1, array2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement