Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3686607

Browse files
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

‎problem-29.js

Lines changed: 14 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /