Skip to content

Instantly share code, notes, and snippets.

@valterbarros
Last active August 1, 2023 12:25
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 valterbarros/0d89a1ebabb01b5b2e1ad28825bd5156 to your computer and use it in GitHub Desktop.
Save valterbarros/0d89a1ebabb01b5b2e1ad28825bd5156 to your computer and use it in GitHub Desktop.
import {
isTimeElapsedBeforeEndTime,
getDateTimeElapsedSincePageLoaded,
getDurationBetweenTimes,
} from '@/utils/date';
class myMap extends Map {
deleteByValue(valueToRemove) {
console.log('delete', this, valueToRemove)
this.forEach((value, key) => {
if (value === valueToRemove) this.delete(key);
});
}
}
let mapper = new myMap();
const signer1 = { signer: 'Valter' };
const signer2 = { signer: 'Maris' };
const signer3 = { signer: 'C3PO' };
const signature1 = { color: 'red' }
const signature2 = { color: 'yellow' }
const deleteIt = (signature) => {
mapper.forEach((value, key) => {
if (value === signature) mapper.delete(key);
});
}
describe('MapTests', () => {
it('should remove based on value instead of key', () => {
mapper.set(signer1, signature1);
mapper.set(signer1, signature2);
mapper.set(signer3, signature1);
// deleteIt(signature2);
mapper.deleteByValue(signature2);
expect([...mapper.entries()]).toMatchObject([
[
{
"signer": "C3PO"
},
{
"color": "red"
}
]
]);
});
it('should remove based on key', () => {
mapper.set(signer1, signature1);
mapper.set(signer1, signature2);
mapper.set(signer3, signature1);
mapper.delete(signer1);
expect([...mapper.entries()]).toMatchObject([
[
{
"signer": "C3PO"
},
{
"color": "red"
}
]
]);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment