match property js

Solutions on MaxInterview for match property js by the best coders in the world

showing results for - "match property js"
Candice
06 Sep 2020
1const matchProperty = (data, compare) => {
2	let compareIn = Object.keys(compare)
3	let inData = Object.keys(data)
4	const newInData = inData
5		.slice(0, compareIn.length)
6		.map((v, i) => {
7			if (v !== compareIn[i]) {
8				return compareIn[i]
9			}
10		})
11		.map((v) => v !== undefined && true)
12	return newInData.includes(true) ? false : true
13}
14
15let data = { directory: null, pattern: null, fileName: null, extension: null }
16let compare = { directory: null, patternx: null }
17
18let res = matchProperty(data, compare)
19console.log(res)
Jerónimo
23 Jun 2016
1export const matchProperty = (data: Record<string, any>, compare: Record<string, any>): boolean => {
2	let compareIn = Object.keys(compare)
3	const newInData = compareIn.map((v) => `${v}` in data)
4	return newInData.includes(false) ? false : true
5}