Skip to content

Commit 3686607

Browse files
committed
add new problem invert values
1 parent 3319682 commit 3686607

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: problem-29.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*Given a set of numbers, return the additive inverse of each.
2+
Each positive becomes negatives, and the negatives become positives.
3+
You can assume that all values are integers.*/
4+
5+
function invert(array) {
6+
const arr = [];
7+
if (array.length == 0)
8+
return array
9+
for (let e of array) {
10+
arr.push(-e)
11+
}
12+
13+
return arr;
14+
}

0 commit comments

Comments
 (0)