Skip to content

Instantly share code, notes, and snippets.

View 3zrv's full-sized avatar
:shipit:
418

Mohamed Sayed 3zrv

:shipit:
418
View GitHub Profile
@3zrv
3zrv / validate.js
Created May 10, 2023 08:27
Joi validation example
import Joi from 'joi';
import _ from 'lodash';
const validate = (schema) => (req, res, next) => {
const validSchema = _.pick(schema, ['params', 'query', 'body']);
const object = _.pick(req, Object.keys(validSchema));
const { error, value } = Joi.compile(validSchema)
.prefs({ errors: { label: 'path', wrap: { label: false } }, abortEarly: false })
.validate(object);
if (error) {
@3zrv
3zrv / challenge.md
Created January 27, 2022 21:43
SDE coding challenge at Amazon

Given an array of strings, consisting of an ID and formatted date, return how many times did each ID repeat.

Each single ID should be counted as repeated only if it did occur on a different day, therefore, if one of the IDs repeated in one single day, it should not be counted as a repeation/occurance.

Example:

Given

 visits = [