7 kyu

zero-balanced Array

524 of 1,282aweleshetu

Description:

An array is called zero-balanced if its elements sum to 0 and each element has its corresponding negative (i.e. if there are x elements n, then there must be x negatives -n). For example,

[1, -1, 2, -2] — zero-balanced, sum of elements is 0 + each element has its own negative;
[0, 1, -1] — zero-balanced, 0 is the negative of itself (0 == -0);

[3] — not zero-balanced; sum != 0;
[3, -2, -1] — not zero-balanced, sum == 0, but the array has 3 but not its negative, -3;
[1, 1, 1, 1, -1, 3, -3, -3] — despite having sum == 0 and all elements having their negatives, the latters must have the same amount as their originals, which doesn't comply here (four '1' and one '-1'), therefore, this array is not zero-balanced.

Write a function that returns true if its argument is zero-balanced array, else return false.

Note: an empty array will not sum to 0 since there are no elements in it, therefore, it should be treated as not zero-balanced.

Arrays
Fundamentals

Stats:

CreatedSep 24, 2017
PublishedSep 24, 2017
Warriors Trained2277
Total Skips40
Total Code Submissions11014
Total Times Completed1282
JavaScript Completions524
C# Completions114
Python Completions598
Ruby Completions104
Crystal Completions10
Total Stars23
% of votes with a positive feedback rating84% of 323
Total "Very Satisfied" Votes244
Total "Somewhat Satisfied" Votes57
Total "Not Satisfied" Votes22
Total Rank Assessments12
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • aweleshetu Avatar
  • GiacomoSorbi Avatar
  • Voile Avatar
  • Souzooka Avatar
  • user9644768 Avatar
  • hobovsky Avatar
  • 4500zenja1 Avatar
Ad