Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,804 members, 7,820,815 topics. Date: Tuesday, 07 May 2024 at 10:20 PM

Debug This Code At Your Spare Time. - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Debug This Code At Your Spare Time. (890 Views)

Please Who Can Help Me Debug This Testing Code? / Someone, Please Help Debug This Code / Can Somebody Help Me Debug This? (2) (3) (4)

(1) (Reply) (Go Down)

Debug This Code At Your Spare Time. by Maskyy(m): 4:13am On Jan 11, 2020
someone should check out this my js code. ERROR: instead of 3 iteration output, it output 9 iterations. just bordering me since.


let z = [
{id : 1 , age : 20},
{id : 2 , age : 15},
{id : 3 , age : 30}
]

let Obj = {
oder1:{
id : 1,
name : 'Ben',
club : 'chelsea',
food : 'pie',
stat : 500
},
oder2:{
id : 4,
name : 'Bolu',
club : 'ManU',
food : 'saws',
stat : 700
},

oder3:{
id : 2,
name : 'Julie',
club : 'ManU',
food : 'saws',
stat : 700
}

}

z.filter(value => {
for (const key in Obj) {
if (Obj.hasOwnProperty(key)) {
const element = Obj[key];
value.id===element.id ? console.log(`hi ${element.name}. Id is correct`) : console.log(`invalid Id ${!String()}`);
}
}});
Re: Debug This Code At Your Spare Time. by gbolly1151(m): 8:29am On Jan 11, 2020
I suggest to save it again and run
Re: Debug This Code At Your Spare Time. by peterincredible: 9:19am On Jan 11, 2020
array.filter() must return a boolean you are not returning anything guy put your return in the for() state ment where your checked if return element.id === value.id ? whatever : whatever

i hope it works cause no light for me to test wetin i talk but i just observe u didnt return anything
Re: Debug This Code At Your Spare Time. by Maskyy(m): 9:00am On Jan 12, 2020
it as being fixed. Thanks to your responds.

(1) (Reply)

Need Help With Application/program For My New Laptop / Website Design / Download E-commerce System Using Php/mysqli With Free Source Code

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 6
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.