Skip to content

Instantly share code, notes, and snippets.

@krrskl
Created June 29, 2022 14:19
Show Gist options
  • Save krrskl/34508c281655087974526f05905b4b66 to your computer and use it in GitHub Desktop.
Save krrskl/34508c281655087974526f05905b4b66 to your computer and use it in GitHub Desktop.
This code base is a test make to midudev by recruiter from arc.dev
import assert from 'node:assert';
const firstLeftArray = [
{ id: 0, name: 'Miguel' },
{ id: 1, name: 'Justin' },
{ id: 3, name: 'Test' },
];
const firstRightArray = [
{ id: 0, email: '[email protected]' },
{ id: 2, email: '[email protected]' },
{ id: 3, email: '[email protected]' },
];
const secondLeftArray = [
{ id: 0, name: 'Miguel' },
{ id: 1, name: 'Justin' },
];
const secondRightArray = [
{ id: 0, email: '[email protected]' },
{ id: 2, email: '[email protected]' },
];
const thirdLeftArray = [
{ id: 0, name: 'Miguel', email: '[email protected]' },
{ id: 1, name: 'Justin' },
{ id: 3, name: 'Test', email: '[email protected]' },
];
const thirdRightArray = [
{ id: 0, lastName: 'Duran' },
{ id: 2, email: '[email protected]', lastName: 'Faker' },
{ id: 3, email: '[email protected]', lastName: 'Faker2' },
];
const firstExpectedOutput = [
{ id: 0, name: 'Miguel', email: '[email protected]' },
{ id: 3, name: 'Test', email: '[email protected]' },
];
const secondExpectedOutput = [
{ id: 0, name: 'Miguel', email: '[email protected]' },
];
const thirdExpectedOutput = [
{ id: 3, name: 'Test', email: '[email protected]', lastName: 'Faker2' },
];
function innerJoin(leftArray, rightArray, key) {
// do the magic here
}
const firstResult = innerJoin(firstLeftArray, firstRightArray, 'id');
const secondResult = innerJoin(secondLeftArray, secondRightArray, 'id');
const thirdResult = innerJoin(thirdLeftArray, thirdRightArray, 'email');
assert.deepStrictEqual(
firstExpectedOutput,
firstResult,
'❌ First expected output not match'
);
console.log('✅ First expected output match');
assert.deepStrictEqual(
secondExpectedOutput,
secondResult,
'❌ Second expected output not match'
);
console.log('✅ Second expected output match');
assert.deepStrictEqual(
thirdExpectedOutput,
thirdResult,
'❌ Third expected output not match'
);
console.log('✅ Third expected output match');
@krrskl
Copy link
Author

krrskl commented Jun 29, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment