Welcome, Guest: Join Nairaland / LOGIN! / Trending / Recent / New
Stats: 2,758,776 members, 6,557,924 topics. Date: Wednesday, 27 October 2021 at 01:12 AM

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

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

Someone, Please Help Debug This Code / Can Somebody Help Me Debug This? / Java Programmers ,I Need Help Fixing This Code. (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)

How Do I Solve This Python (anaconda) Problem / What Are The Key Factors To Build An Excellent Business Mobile App? / Re:

(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 - 2021 Oluwaseun Osewa. All rights reserved. See How To Advertise. 21
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.