From dec23661b1a5d0317a3ff1b20cfa53a693a9074f Mon Sep 17 00:00:00 2001 From: Maryam Qays <70143196+maryamaltuma@users.noreply.github.com> Date: Sun, 16 Oct 2022 09:51:25 +0300 Subject: [PATCH] Maryam Qays Kadhim --- index.js | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index b2d55d2..58526b9 100644 --- a/index.js +++ b/index.js @@ -29,8 +29,27 @@ } ]; // TO-DO - // Promise object/function here - // 2 params, 1: list, 2: target to match - // return: Promise, resolve: list after filteration, reject: error message - // TO-DO -})(); \ No newline at end of file + + const locPerson = (pers, Target = 16)=>{ + return pro = new Promise((resolve,reject)=>{ + const user = PERSONS.filter(PERSONS => PERSONS && PERSONS.age === Target); + + if (user){ + resolve(user) + } + else{ + reject("No person with this age was found") + } + }); + + } + + locPerson().then((res) => { + console.log(res) + }) + .catch((error) => { + console.log(error) + }) + +})(); +