6 kyu

Sum two arrays

1,856 of 3,417ggwilliams

Description:

Your task is to create a function called addArrays, which takes two arrays consisting of integers, and returns the sum of those two arrays.

The twist is that (for example) [3,2,9] does not equal 3 + 2 + 9, it would equal '3' + '2' + '9' converted to an integer for this kata, meaning it would equal 329. The output should be an array of the sum in a similar fashion to the input (for example, if the sum is 341, you would return [3,4,1]). Examples are given below of what two arrays should return.

[3,2,9],[1,2] --> [3,4,1]
[4,7,3],[1,2,3] --> [5,9,6]
[1],[5,7,6] --> [5,7,7]
[3,2,9],[1,2] --> [3,4,1]
[4,7,3],[1,2,3] --> [5,9,6]
[1],[5,7,6] --> [5,7,7]
[3, 2, 9], [1, 2]    // [3, 4, 1]
[4, 7, 3], [1, 2, 3] // [5, 9, 6]
[1], [5, 7, 6]       // [5, 7, 7]
{3,2,9} + {1,2}   = {3,4,1}
{4,7,3} + {1,2,3} = {5,9,6}
{1}     + {5,7,6} = {5,7,7}
{3,2,9} + {1,2}   = {3,4,1}
{4,7,3} + {1,2,3} = {5,9,6}
{1}     + {5,7,6} = {5,7,7}
{3,2,9} + {1,2}   = {3,4,1}
{4,7,3} + {1,2,3} = {5,9,6}
{1}     + {5,7,6} = {5,7,7}
{3,2,9} + {1,2}   = {3,4,1}
{4,7,3} + {1,2,3} = {5,9,6}
{1}     + {5,7,6} = {5,7,7}

If both arrays are empty, return an empty array.

In some cases, there will be an array containing a negative number as the first index in the array. In this case treat the whole number as a negative number. See below:

[3,2,6,6],[-7,2,2,8] --> [-3,9,6,2] # 3266 + (-7228) = -3962
[3,2,6,6],[-7,2,2,8] --> [-3,9,6,2] # 3266 + (-7228) = -3962
[3, 2, 6, 6], [-7, 2, 2, 8] // [-3, 9, 6, 2] as 3266 + (-7228) = -3962
{3,2,6,6} + {-7,2,2,8} = {-3,9,6,2} // 3266 + (-7228) = -3962
{3,2,6,6} + {-7,2,2,8} = {-3,9,6,2} // 3266 + (-7228) = -3962
{3,2,6,6} + {-7,2,2,8} = {-3,9,6,2} // 3266 + (-7228) = -3962
{3,2,6,6} + {-7,2,2,8} = {-3,9,6,2} // 3266 + (-7228) = -3962
Algorithms

Stats:

CreatedSep 21, 2017
PublishedSep 21, 2017
Warriors Trained6968
Total Skips200
Total Code Submissions49989
Total Times Completed3417
JavaScript Completions1856
Python Completions1493
Rust Completions59
Ruby Completions64
Total Stars104
% of votes with a positive feedback rating85% of 612
Total "Very Satisfied" Votes459
Total "Somewhat Satisfied" Votes119
Total "Not Satisfied" Votes34
Total Rank Assessments90
Average Assessed Rank
6 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • ggwilliams Avatar
  • ZozoFouchtra Avatar
  • Chrono79 Avatar
  • imjasonmiller Avatar
  • KenKamau Avatar
  • clcraig Avatar
  • user9644768 Avatar
  • Glyxerine Avatar
  • khlivnyuk Avatar
  • ejini战神 Avatar
  • Rbaha07 Avatar
Ad