Skip to content

Instantly share code, notes, and snippets.

@krrskl
Created June 29, 2022 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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: 'miduga@gmail.com' },
{ id: 2, email: 'alpha@gmail.com' },
{ id: 3, email: 'test@gmail.com' },
];
const secondLeftArray = [
{ id: 0, name: 'Miguel' },
{ id: 1, name: 'Justin' },
];
const secondRightArray = [
{ id: 0, email: 'miduga@gmail.com' },
{ id: 2, email: 'alpha@gmail.com' },
];
const thirdLeftArray = [
{ id: 0, name: 'Miguel', email: 'miduga@gmail.com' },
{ id: 1, name: 'Justin' },
{ id: 3, name: 'Test', email: 'test@gmail.com' },
];
const thirdRightArray = [
{ id: 0, lastName: 'Duran' },
{ id: 2, email: 'alpha@gmail.com', lastName: 'Faker' },
{ id: 3, email: 'test@gmail.com', lastName: 'Faker2' },
];
const firstExpectedOutput = [
{ id: 0, name: 'Miguel', email: 'miduga@gmail.com' },
{ id: 3, name: 'Test', email: 'test@gmail.com' },
];
const secondExpectedOutput = [
{ id: 0, name: 'Miguel', email: 'miduga@gmail.com' },
];
const thirdExpectedOutput = [
{ id: 3, name: 'Test', email: 'test@gmail.com', 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