We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 72dc07e commit f1f98a2Copy full SHA for f1f98a2
two_sum/main.js
@@ -0,0 +1,14 @@
1
+function twoSum(numbers, target) {
2
+ let result;
3
+ for(let i = 0; i < numbers.length - 1; i++) {
4
+ let sub = target - numbers[i];
5
+ for(let j = i + 1; j < numbers.length; j++) {
6
+ if(sub === numbers[j]) {
7
+ result = [numbers[i], numbers[j]];
8
+ }
9
10
11
+ return result;
12
+}
13
+
14
+module.exports = twoSum;
two_sum/main.test.js
@@ -0,0 +1,25 @@
+const twoSum = require('./main');
+test('the array of [1,2] and the parameter 3 returns [1,2]', () => {
+ expect(twoSum([1,2], 3)).toStrictEqual([1,2]);
+});
+test('the array of [2,2,1] and the parameter 4 returns [2,2]', () => {
+ expect(twoSum([2,2,1], 4)).toStrictEqual([2,2]);
+test('the array of [1,5,3] and the parameter 4 returns [1,3]', () => {
+ expect(twoSum([1,5,3], 4)).toStrictEqual([1,3]);
15
+test('the array of [5,3,1] and the parameter 4 returns [3,1]', () => {
16
+ expect(twoSum([5,3,1], 4)).toStrictEqual([3,1]);
17
18
19
+test('the array of [1234,5678,9012] and the parameter 14690 returns [5678, 9012]', () => {
20
+ expect(twoSum([1234,5678,9012], 14690)).toStrictEqual([5678,9012]);
21
22
23
+test('the array of [1,2,3] and the parameter 4 returns [1,3]', () => {
24
+ expect(twoSum([1,2,3], 4)).toStrictEqual([1,3]);
25
0 commit comments