These are chat archives for FreeCodeCamp/HelpJavaScript

20th
Nov 2018
CarlW
@ugglr
Nov 20 2018 14:24

Greetings, I am having trouble with a challenge called profile lookup in the javascript basics block
I think I'm getting the right output, but will not pass. Anyone willing to help?

This is my function:

```
function lookUpProfile(name, prop){
// Only change code below this line
contacts.forEach(o => {
if(o.firstName === name) {
if(o.prop !== "") {
return o[prop];
} else {
return "No such property";
}
}
});
return "No such contact";
// Only change code above this line
}
´´´

function lookUpProfile(name, prop){
// Only change code below this line
contacts.forEach(o => {
if(o.firstName === name) {
if(o.prop !== "") {
return o[prop];
} else {
return "No such property";
}
}
});
return "No such contact";
// Only change code above this line
}
Adel
@AdelMahjoub
Nov 20 2018 14:56
CarlW
@ugglr
Nov 20 2018 14:57
@AdelMahjoub Hi thanks, I have taken a look at it but I want to solve it with a forEach loop instead of a for loop
Adel
@AdelMahjoub
Nov 20 2018 14:59
@ugglr >Note: There is no way to stop or break a forEach() loop other than by throwing an exception. If you need such behaviour, the .forEach() method is the wrong tool, use a plain loop instead
Nate Mallison
@NJM8
Nov 20 2018 15:09
Any of you use VsCode and have you turned off intellisense's function parameter suggestion box. I can't stand that thing.
Blauelf
@Blauelf
Nov 20 2018 15:25
I thought it was VSCode's main feature (in combination with TypeScript)
Johnny
@JohnnyBizzel
Nov 20 2018 16:39
@NJM8 If you don't like intellisense there is always notepad :joy:
Christopher McCormack
@cmccormack
Nov 20 2018 16:41
I also think it's a bit aggressive, sometimes I need it but I find myself interacting with it more to get it out of my way than to use it
Blauelf
@Blauelf
Nov 20 2018 16:47
It can't be worse than the autocompletion in CodinGame. It even autocompletes after you completed, duplicating parts of the variable name.
Christopher McCormack
@cmccormack
Nov 20 2018 16:48
VS Code will occasionally do that to me as well, such a pain in the butt.
Blauelf
@Blauelf
Nov 20 2018 16:48
And in JavaScript, there rarely is a hard fail, rather things turn into undefined and NaN before crashing.
Nate Mallison
@NJM8
Nov 20 2018 17:06
@JohnnyBizzel LOL
I don't mind the autocomplete it's the giant floating function parameter box I can't stand. It seems to always be in the way.
Christopher McCormack
@cmccormack
Nov 20 2018 17:09
Is this not the most recursive error message...?
PS C:\Users\chris> scoop install git
Scoop uses Git to update itself. Run 'scoop install git' and try again.
Nate Mallison
@NJM8
Nov 20 2018 17:10
I think you have to run scoop install git
:laughing:
Christopher McCormack
@cmccormack
Nov 20 2018 17:11
I've never even seen scoop but it's kind of neat
git is extremely slow on my windows pc working with the fcc repo and thought it might be a problem with WSL so testing out some windows stuff
Blauelf
@Blauelf
Nov 20 2018 17:26
Every time I try the PowerShell, it does unexpected things. So many things I am used to just don't work, or require adding magic characters at the right position so it's not interpreted. But having output assigned to variables is pretty nice.
I might be a bit outdated, doing batch since MS-DOS 6.20 :D
Christopher McCormack
@cmccormack
Nov 20 2018 17:42
it all seems like magic to me
I guess if you were an admin it might be better
Keggatron
@Keggatron
Nov 20 2018 17:56
Hi guys, I'm trying to figure out the best way to get data from deeply nested objects
{
          id: 1,
          departmentId: 19,
          description: 'Area-1',
          positions: [
            {
              id: 31,
              description: 'Position-1',
              employee: {
                firstName: 'Joe',
              },
              days: [
                {
                  day: 'Tuesday',
                  weekIndex: 2,
                  dayNumber: 2,
                  shift:
                    {
                      startTime: 'November 4, 2018 07:00:00',
                      endTime: 'November 4, 2018 19:00:00',
                      request: {
                        type: 'swap',
                        swapName: 'Swap 1',
                        swapTo: {
                          id: 1,
                          firstName: 'John',
                          lastName: 'lastName',
                        },
                      },
                    },
                },
            },
},
I'm looking to match the swapNames and return the position array for that
Nate Mallison
@NJM8
Nov 20 2018 18:06
@Keggatron I have to do this sometimes and you can end up with errors if the object doesn't exist yet or you don't pass the right sequence. I use Lodash's get function, nice and easy, you pass it the object, the path, and the default of what you want to return if not found. _.get(myObj, "some.deeply.nested.data.I.need.why.is.this.down.so.far", [])
in this case it would return an empty array if not found
Or you could make your own recursive function to do the same.
Keggatron
@Keggatron
Nov 20 2018 18:07
Thanks @NJM8 I'll give this a shot
Hey @NJM8 I'm not seeing a .get function in the Lodash docs
Keggatron
@Keggatron
Nov 20 2018 18:19
thanks
Keggatron
@Keggatron
Nov 20 2018 18:26
Hey Nate, so I'm not entirely sure how this would work. So say I have Swap 1 as my swap name. I need to find the object with Swap 1 as a swapName and I'd like to find the startTime and endTime of that shift, as well as the employee.firstName. Looking at the examples in the docs I'm not sure if the .get method would work. Any idea?
Simon Cordova
@gbsimon87
Nov 20 2018 18:39
Hey all :)
Adel
@AdelMahjoub
Nov 20 2018 18:43
hey
Simon Cordova
@gbsimon87
Nov 20 2018 18:48
Anybody ever use Redux Form? https://redux-form.com/6.6.2/
Nate Mallison
@NJM8
Nov 20 2018 19:45
@Keggatron Oh sorry I miss-understood what you are doing.
@gbsimon87 No one ever.
@Keggatron Does the swap request have to be so deeply nested? Why not put it right at the user level and store it's times and stuff there as well?
I assume you are trying to match swap requests so you can make a swap?
Keggatron
@Keggatron
Nov 20 2018 19:48
yes
Nate Mallison
@NJM8
Nov 20 2018 19:48
Do you have control of the data?
Keggatron
@Keggatron
Nov 20 2018 19:48
no
I can't really adjust the data
Nate Mallison
@NJM8
Nov 20 2018 19:50
Do you have to loop through all the employees at the positions level then through all their days? drill down to the request and match them up?
Like are you switching shifts between employees?
Keggatron
@Keggatron
Nov 20 2018 19:57
yes that's correct
Nate Mallison
@NJM8
Nov 20 2018 20:00
Hmm, how many employees and days we talking about here?
Keggatron
@Keggatron
Nov 20 2018 20:04
quite a few
the swap will occur between only two employees
Brad
@bradtaniguchi
Nov 20 2018 20:08
The worst kinda bugs are the king of bugs that preventing you from fixing other bugs
Nate Mallison
@NJM8
Nov 20 2018 20:10
@Keggatron I would break it down into smaller functions, a main loop through the employees, pass off to a function to see if that employees days have a swap, if so return the indexs and swap name, continue on until you can find the swaps that match up, then pass off the matches to a swap function to perform the swap.
Keggatron
@Keggatron
Nov 20 2018 20:11
ok great thanks @NJM8. I'll try and get that going. Thanks for the help.
Brad
@bradtaniguchi
Nov 20 2018 20:44
grrr breaking changes in "minor" package changes :/
alpox
@alpox
Nov 20 2018 22:20
@bradtaniguchi Good for extra adrenaline!
Brad
@bradtaniguchi
Nov 20 2018 22:21
"I don't open many bugs, but when I do its cuse my crap is breaking"
Jason Luboff
@JLuboff
Nov 20 2018 23:06
You know you’re a programmer when you get an email during your vacation of a “glitch” and can’t rest until you investigate even though you’re not supposed to 😂
Brad
@bradtaniguchi
Nov 20 2018 23:41
@JLuboff Good thing I'm not a real programmer 80% of the time :P