Created
February 4, 2025 18:57
-
-
Save JavierSolis/dcb2f3908034409b71c17ee335f507f7 to your computer and use it in GitHub Desktop.
test tecnico, se puede ver en https://jtest.ceroauno.de/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Let M be a not empty set of integer numbers, find the first subset of 2 numbers of M which sum N. For instance, let's say we've got a set of numbers [2, 5, 8, 14, 0] and N = 10, the resulting subset should be [2, 8]. | |
Challenge | |
You're required to create a function that receives an array (M) and integer value (N). This function has to return an array of the first possible solution. | |
🚨 We're looking to someone who can imagine future problems while is coding. | |
*/ | |
function getPair(m,n, groupSize = 2){ | |
for (let i1 = 0; i1 < m.length; i1++) { | |
const val1 = m[i1]; | |
for (let i2 = i1+1; i2 < m.length; i2++) { | |
const val2 = m[i2]; | |
if(val1+val2==n){ | |
return [val1,val2]; | |
} | |
} | |
} | |
return []; | |
} | |
describe('Test Suite', async () => { | |
//casos basicos | |
await it('unico resultado posible', async () => { | |
expect(getPair([1,2],3)).to.equal([1,2]); | |
}); | |
await it('primer resultado posible', async () => { | |
expect(getPair([1,2,3,4,5,6],7)).to.equal([1,6]); | |
}); | |
//vacios | |
await it('dado un conjunto se espera solución vacía', async () => { | |
expect(getPair([1,100,10],3)).to.equal([]); | |
}); | |
await it('dado un conjunto vacío se espera solución vacía', async () => { | |
expect(getPair([],3)).to.equal([]); | |
}); | |
//casos negativos | |
await it('dado un conjunto y N cero, se espera solución de positivo y negativo', async () => { | |
expect(getPair([-1,-3,5,1,100,-3,10],0)).to.equal([-1,1]); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment