These are chat archives for FreeCodeCamp/Help

30th
Mar 2018
Kevin
@kevinwr
Mar 30 2018 00:01
haha. I just found out my code leads to an unintended error. Dammit.
Kyle Holm
@thekholm80
Mar 30 2018 00:02
that's the story of my life. try something new, spend 4 hours trying to figure out why it doesn't work
Kevin
@kevinwr
Mar 30 2018 00:03
I know why it's not working...just need to come up with a solution
brianna4444
@brianna4444
Mar 30 2018 01:11
Hi guys, I need help with the JS intermediate algorithm challenges for front end cert. Really lost and its too much to post on these chats for help. Looking to pay someone to tutor me remotely. Please message me if you'd be interested.
jadefox10200
@jadefox10200
Mar 30 2018 05:10
@DarrenfJ
Aditya
@ezioda004
Mar 30 2018 06:04
@brianna4444 You can instead post what you've done so far and where are you stuck in any help room, and I'm sure someone will help you out.
disiduohui
@disiduohui
Mar 30 2018 08:51
<style>
.larger-image {
width: 500px;
}
</style>
how put this code?
maybe i got a wrong palce
Aditya
@ezioda004
Mar 30 2018 08:54
@disiduohui In the <head> tag, is this a fcc challenge?
disiduohui
@disiduohui
Mar 30 2018 08:55
yes
but i can not pass the run test
this is css
Aditya
@ezioda004
Mar 30 2018 08:59
Can you tell the challenge name?
disiduohui
@disiduohui
Mar 30 2018 09:00
Size your Images
May Kittens Devour Your Soul
@diomed
Mar 30 2018 09:02
@disiduohui do u need to size them larger, or smaller?
Aditya
@ezioda004
Mar 30 2018 09:03
@disiduohui As far as I can see .larger-image is an example, you need to make .smaller-image class and give that class to your <img>element
disiduohui
@disiduohui
Mar 30 2018 09:03
yes,smaller
May Kittens Devour Your Soul
@diomed
Mar 30 2018 09:04
@disiduohui example shows u where to put code
hello @ezioda004 :cat: :wave:
disiduohui
@disiduohui
Mar 30 2018 09:05
ok,i will show my put,because i think i obey the example but can not to run

<link href="https://fonts.gdgdocs.org/css?family=Lobster" rel="stylesheet" type="text/css">

<style>
.smaller-image {
width:100px;
}
.red-text {
color: red;
}

h2 {
font-family: Lobster, Monospace;
}

p {
font-size: 16px;
font-family: Monospace;
}
</style>

what's wrong?
May Kittens Devour Your Soul
@diomed
Mar 30 2018 09:09
it's all good
now you need to apply that class to html below
like u did with red-text
disiduohui
@disiduohui
Mar 30 2018 09:10
ok,i will try .Thank you !
Aditya
@ezioda004
Mar 30 2018 09:12
@diomed :sparkles:
Daniel
@dkapexhiu
Mar 30 2018 10:36
Hello! Please how to solve this error in nearby search in google maps api:
InvalidValueError: setPosition: not a LatLng or LatLngLiteral: in property lat: not a number?
Sandip Shrestha
@saninmersion
Mar 30 2018 11:02
@dkapexhiu the error seems self explanatory. The value you are providing for "setPosition" property (probably in the mapProps object) is not a valid LatLng. To get a valid googlemap Latlong use new google.maps.LatLng($latitude, $longitude)
Daniel
@dkapexhiu
Mar 30 2018 11:04
i have been using this:
var request = {
        location: new google.maps.LatLng(48.8587741, 2.2069771),
        radius: '500',
        type: ['restaurant']
};
but when i do console.log(request.location.lat) it outputs a function instead of a value
Sandip Shrestha
@saninmersion
Mar 30 2018 11:22
@dkapexhiu it is supposed to return a function. new google.maps.LatLng() basically creates a class or so I think
object*
Daniel
@dkapexhiu
Mar 30 2018 11:25
yes but how can i made the request work and do a nearby search as it is supposed in this guide:
https://developers.google.com/maps/documentation/javascript/places#place_search_requests
Sandip Shrestha
@saninmersion
Mar 30 2018 11:29
@dkapexhiu what's not working
Daniel
@dkapexhiu
Mar 30 2018 11:31
i am trying to get the restaurants near a place in google maps but it throws me error in LatLng
this is what i was trying to do:
$('#getGoogleRestaurants').click(function(){
    var request = {
        location: new google.maps.LatLng(48.8587741, 2.2069771),
        radius: '500',
        type: ['restaurant']
    };

    var service = new google.maps.places.PlacesService(map);
    service.nearbySearch(request, callback);

    function callback(results, status) {
        if (status == google.maps.places.PlacesServiceStatus.OK) {
          for (var i = 0; i < results.length; i++) {
            var place = results[i];
            addMarker(place.geometry.location.lat, place.geometry.location.lng, place.name, place.id);
          }
        }
    }
});
Sandip Shrestha
@saninmersion
Mar 30 2018 11:37
var service = new google.maps.places.PlacesService(map); do you have a variable value "map" for that line?
Daniel
@dkapexhiu
Mar 30 2018 11:46
yes i have
map = new google.maps.Map(document.getElementById('map'), {
        center: {lat: 48.8587741, lng: 2.2069771},
        zoom: 10
    });
Stephen James
@sjames1958gm
Mar 30 2018 12:23
This message was deleted
@dkapexhiu Is the error coming from addMarker?
Kyle Holm
@thekholm80
Mar 30 2018 13:51
good morning, /help
Kevin
@kevinwr
Mar 30 2018 13:53
hola. morning
how's it going, Kyle?
Kyle Holm
@thekholm80
Mar 30 2018 13:54
@kevinwr Pretty darn good, you? looking forward to a slow day today
Kevin
@kevinwr
Mar 30 2018 13:54
Hungry...and waiting to hear back from Florida State University about my admissions; I'm transferring to their online Computer Science program
or...trying to
Kyle Holm
@thekholm80
Mar 30 2018 13:55
oh, good luck! I hope it works out
Kevin
@kevinwr
Mar 30 2018 13:55
hate this waiting around thing though. It's driving me batty just waiting.
yeah, me too. I really need this
thank you
slow day today, huh?
at work?
Kyle Holm
@thekholm80
Mar 30 2018 13:55
at work, yeah
so far
Kevin
@kevinwr
Mar 30 2018 13:55
what you do for work?
Kyle Holm
@thekholm80
Mar 30 2018 13:56
i work in PR & Communications, my job is to interface with publishing companies
Kevin
@kevinwr
Mar 30 2018 13:56
oh, cool. Like it?
Kyle Holm
@thekholm80
Mar 30 2018 13:56
it's not so bad
sometimes I wish I was doing something else, but who doesn't?
Kevin
@kevinwr
Mar 30 2018 13:57
how long you been doing that?
Kyle Holm
@thekholm80
Mar 30 2018 13:57
i've been in this position for about 5 years
Kevin
@kevinwr
Mar 30 2018 13:58
So you going through FCC curriculum?
Kyle Holm
@thekholm80
Mar 30 2018 13:58
yeah, nearly done
Kevin
@kevinwr
Mar 30 2018 13:58
oh really? nice
with all of it?
Kyle Holm
@thekholm80
Mar 30 2018 13:58
yep, just 3 projects left
Kevin
@kevinwr
Mar 30 2018 13:58
dang. nice, man. Why did you start FCC?
Kyle Holm
@thekholm80
Mar 30 2018 13:58
Feb 2017
if i remember right
Kevin
@kevinwr
Mar 30 2018 13:59
well...that's cool, but I was wondering why you started? what's your goal?
lol
Kyle Holm
@thekholm80
Mar 30 2018 14:00
haha
i enjoy programming and needed a hobby
and if something happens with my job, it's nice to have other skills to fall back on
Kevin
@kevinwr
Mar 30 2018 14:01
that's cool. Fair enough. Yeah...programming seems like it's a valuable skill to have, and likely will be into the future.
Also teaches you how to think differently
Kyle Holm
@thekholm80
Mar 30 2018 14:01
it's a lot of fun
Kevin
@kevinwr
Mar 30 2018 14:01
and solve problems - a needed skill in anything
yeah it is
Kyle Holm
@thekholm80
Mar 30 2018 14:01
except webpack. there's nothing fun about webpack
Kevin
@kevinwr
Mar 30 2018 14:03
I am going the CS route because it provides an opportunity to learn new skills, and the fact that it is fun. I did a bit of VB and website coding back 15 or so years ago. I remember when you styled html elements in HTML. Have come quite a long ways.
what's webpack?
Kyle Holm
@thekholm80
Mar 30 2018 14:03
it's one of the tools in the React ecosystem
Claudio Restifo
@Marmiz
Mar 30 2018 14:04
@thekholm80 apparently the new version should come working without configurations....
In the meantime I shiver in fear every time I have to touch a single line in webpack.config
Kevin
@kevinwr
Mar 30 2018 14:04
I've heard of react, but don't even know what that is. Obviously I'm a complete noob. haha
Kyle Holm
@thekholm80
Mar 30 2018 14:04
@Marmiz i saw one of the project leads teasing zero config on twitter when 4.0 was still in alpha, but i've not tried it
@kevinwr haha well, you'll get there
I would like to take some CS classes. my knowledge of theory is sorely incomplete
all i've done is practical application
Kevin
@kevinwr
Mar 30 2018 14:09
yeah, I hope so. Still trying to figure out exactly what route I want to go with everything. I think I would like to be a software app developer. So eventually I'm going to be diving into C#, C++, Java and some of those languages. One reason I'm starting FCC is because as an app developer, one thing you'd want is cross-platform compatibility and having a platform you can access online. This means learning web technologies so I can create a cross-platform ecosystem...if that makes sense.
Kyle Holm
@thekholm80
Mar 30 2018 14:11
I've always heard that learning any single language will make it much easier to learn another language, and I think that's very true. You said you had VB experience, I started with basic then VBA and I think it really helped me with JavaScript - and now i'm learning some python and I'm amazed at how easy it's been to pick up
Kevin
@kevinwr
Mar 30 2018 14:12
but the world is wide open to me right now, so I'm sure things will narrow down for me as I go. I guess I just love the idea of creating and developing new things. I want to have that ability to create something that tons of people use, helps them in their life, and helps shape the future for people.
Yeah...there is lots of similarity between the languages
some people would disagree with me, but I feel Javascript is a great first programming language because it's easy to pick-up, widely used and in-demand, and it teaches the core fundamentals of programming that would easily transfer to other more "difficult" languages like C# or C++
Also, there are a lot of resources available for JS, which is a huge benefit.
with some other languages, it's hard to find good resources to learn from
sorry...I sometimes I get to rambling and can't seem to shut up
Kyle Holm
@thekholm80
Mar 30 2018 14:17
it's been my experience that any "this vs that" debate in tech largely comes down to personal preference, so you'll get lots of people on both sides using crappy data and personal attacks to justify their position. just ask a group of devs about which text editor is best and watch the room burn down in 20 minutes
Kevin
@kevinwr
Mar 30 2018 14:18
hahaha it's true
there are too many variables to consider when deciding where to start, what tools to use, etc.
Kyle Holm
@thekholm80
Mar 30 2018 14:20
you know, i spent almost a whole week reading articles about django/flask (python) vs express (javascript) for back end servers and at the end it seems it all boiled down to "use whatever you want, it's all good"
Kevin
@kevinwr
Mar 30 2018 14:21
haha. I've noticed that happens a lot
with a lot of these things there are many similarities and likely any option will work for the majority of people. Yet, there are certain technologies that are better suited for certain things; it's a matter of knowing what your goal is/what you need to accomplish. However, like I said, most options will be suitable for most people
Kyle Holm
@thekholm80
Mar 30 2018 14:25
that was a tough lesson for me to learn. most of the compelling arguments i saw in "this vs that" were specific to one giant tech company's use case, and really were not relevant to my little demo apps with a user base <= 1
Kevin
@kevinwr
Mar 30 2018 14:25
haha yep.
Kyle Holm
@thekholm80
Mar 30 2018 14:25
so now i just use whatever i feel like and have fun with it lol
Kevin
@kevinwr
Mar 30 2018 14:26
probably a good route to go
Nazar
@IsaakNazar
Mar 30 2018 14:36
@thekholm80 hey Kyle, do you use plugin transform-class-properties ?
Kyle Holm
@thekholm80
Mar 30 2018 14:37
@IsaakNazar never heard of it, what does it do?
Nazar
@IsaakNazar
Mar 30 2018 14:40
@thekholm80 with this plugin you dont need to bind your functions likethis. handlefunc = this.handlefunc.bind(this)
Kyle Holm
@thekholm80
Mar 30 2018 14:41
@IsaakNazar oh, neat
you can do that natively with arrow functions
Nazar
@IsaakNazar
Mar 30 2018 14:42
@thekholm80 and which method do you prefer? or it doesnt matter?
Kyle Holm
@thekholm80
Mar 30 2018 14:42
i still manually bind mine. if it was good enough for my granddaddy, it's good enough for me
(joking)
Nazar
@IsaakNazar
Mar 30 2018 14:42
:smile:
currently you are workin' on backend sectoin?
*section
Kyle Holm
@thekholm80
Mar 30 2018 14:43
kind of lol, slowly but surely
Nazar
@IsaakNazar
Mar 30 2018 15:52
@thekholm80 are you there?
Kyle Holm
@thekholm80
Mar 30 2018 15:52
mostly
Nazar
@IsaakNazar
Mar 30 2018 15:55
@thekholm80 I'm currently creating reactJS Recipe-box, and there will be component, that includes 'ingredients' and 'instructions'. So, do I need to split ingredients and instructions into separate components, or just single component?
what would be better?
Kyle Holm
@thekholm80
Mar 30 2018 15:56
I try to make my components as small as possible, and have them do just 1 thing. i don't know what best practice is, but that's what has worked best for me
Nazar
@IsaakNazar
Mar 30 2018 15:57
@thekholm80 the more small, the more readable code?
Kyle Holm
@thekholm80
Mar 30 2018 15:58
that's largely why i do it. I like things simple
Nazar
@IsaakNazar
Mar 30 2018 15:58
@thekholm80 got it, thanx
CamperBot
@camperbot
Mar 30 2018 15:58
isaaknazar sends brownie points to @thekholm80 :sparkles: :thumbsup: :sparkles:
:star2: 1756 | @thekholm80 |http://www.freecodecamp.org/thekholm80
Kaz Baig
@kbaig
Mar 30 2018 16:16
@thekholm80 yo dawg
How are you with katas
Kyle Holm
@thekholm80
Mar 30 2018 17:09
@kbaig pretty low ranked, i'm a noob
image.png
Kaz Baig
@kbaig
Mar 30 2018 17:11
@thekholm80 jw what you would do for this one https://www.codewars.com/kata/53f40dff5f9d31b813000774/train/javascript
Kyle Holm
@thekholm80
Mar 30 2018 17:14
i would probably try concatenating the triplets, removing duplicates then use the original triplets to sort
Kyle Holm
@thekholm80
Mar 30 2018 17:20
@InsaneSkull did you need help with this?
if you're just promoting your youtube channel you should delete that before a mod sees it
Aditya
@ezioda004
Mar 30 2018 17:27
:runner: :police_car:
Kyle Holm
@thekholm80
Mar 30 2018 17:27
lol
mstellaluna
@mstellaluna
Mar 30 2018 17:28
@InsaneSkull hello, please be aware advertisting for the sake of social validation and/or financial gains is against our code of conduct, please remove your link
Kyle Holm
@thekholm80
Mar 30 2018 17:29
well i tried lol
mstellaluna
@mstellaluna
Mar 30 2018 17:29
@thekholm80 ty
CamperBot
@camperbot
Mar 30 2018 17:29
mstellaluna sends brownie points to @thekholm80 :sparkles: :thumbsup: :sparkles:
:star2: 1757 | @thekholm80 |http://www.freecodecamp.org/thekholm80
Kyle Holm
@thekholm80
Mar 30 2018 17:29
@mstellaluna how's the beta business? busy as ever?
alessiochiffi
@alessiochiffi
Mar 30 2018 17:29
I am using Redux for other purposes, and I was wondering if is possible using standard React-Navigation with no integration in redux just registering the screens and using this.props.navigation.navigate as a function to navigate
mstellaluna
@mstellaluna
Mar 30 2018 17:30
@thekholm80 its quiet for me because i test certain PRs
Kyle Holm
@thekholm80
Mar 30 2018 17:30
oh nice
mstellaluna
@mstellaluna
Mar 30 2018 17:30
so.. no PRs for curriculum.. no work for me
Kyle Holm
@thekholm80
Mar 30 2018 17:30
like a vacation then
mstellaluna
@mstellaluna
Mar 30 2018 17:30
the calm before the storm
alessiochiffi
@alessiochiffi
Mar 30 2018 17:30
@mstellaluna italiana?
mstellaluna
@mstellaluna
Mar 30 2018 17:31
sono canadese pero i mei genitori sono italiani
alessiochiffi
@alessiochiffi
Mar 30 2018 17:31
bel nome :)
anyone can help me with Redux and React-navigation?
mstellaluna
@mstellaluna
Mar 30 2018 17:31
grazie
Kyle Holm
@thekholm80
Mar 30 2018 17:32
@kbaig so thanks. now i realize how useless i am at sorting arrays
CamperBot
@camperbot
Mar 30 2018 17:32
thekholm80 sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 583 | @kbaig |http://www.freecodecamp.org/kbaig
Kyle Holm
@thekholm80
Mar 30 2018 17:32
lol
Aleksandar B.
@aleksandar-b
Mar 30 2018 17:34
what does getSnapshotBeforeUpdate in new react do? takes like real image snapshot?
aww, they got rid of componentWillUpdate
Aditya
@ezioda004
Mar 30 2018 17:37
I just learned that. Put it back!!
Kyle Holm
@thekholm80
Mar 30 2018 17:38
haha
Kaz Baig
@kbaig
Mar 30 2018 19:22
@thekholm80 I can show you my solution if you want lol
Kyle Holm
@thekholm80
Mar 30 2018 19:22
@kbaig i thought i had it but i don't think i'm smart enough
i'm lucky i'm pretty
Kaz Baig
@kbaig
Mar 30 2018 19:31
@thekholm80 sorry took a bit to find the screenshot I took yesterday - the code didn't seem to save
But yeah that's my solution
Was wondering if there's a better way to do it from a logic perspective
@thekholm80 Def agree that you're pretty, though I'm sure it wasn't totally luck since your parents are likely pretty too ;)
Kyle Holm
@thekholm80
Mar 30 2018 19:33
@kbaig my parents are so pretty. if i was from the south my prom would have been very different
Kaz Baig
@kbaig
Mar 30 2018 19:34
YIKES
Kyle Holm
@thekholm80
Mar 30 2018 19:34
yeah, probably a bit much lol
i think my method was flawed, i'm not sure it had any chance of working
Kaz Baig
@kbaig
Mar 30 2018 19:36
@thekholm80 I went with repeatedly choose the char that only appears in the beginning of the triplets, remove that char from the triplets, repeat
Kyle Holm
@thekholm80
Mar 30 2018 19:39
@kbaig oh, that's smart ... took me a minute to even figure out why that would work
well done
Kaz Baig
@kbaig
Mar 30 2018 19:39
@thekholm80 Had a hunch just staring at it after writing it on a piece of paper and it worked. Lucky me
Kyle Holm
@thekholm80
Mar 30 2018 19:40
the last kata i worked on was all about regex ... i spent probably 2 hours working on it in regex101 only to realize that i forgot to switch to the javascript regex engine, so much of the things i used weren't supported in javascript
:worried: :gun:
Kaz Baig
@kbaig
Mar 30 2018 19:41
Dude I skip regex every time for that reason
It's not standardized
Kyle Holm
@thekholm80
Mar 30 2018 19:41
i thought it was past time to learn, now i hate it even more lol
Kaz Baig
@kbaig
Mar 30 2018 19:41
And also it's a lot of effort to learn something I'm not going to use professionally
Kyle Holm
@thekholm80
Mar 30 2018 19:42
if i ever work as a dev i'd like to be back end, so regex would be useful
Kaz Baig
@kbaig
Mar 30 2018 19:42
Preferably both front and back end are validating but yeah that still makes sense
Kyle Holm
@thekholm80
Mar 30 2018 19:43
but that means i also need to learn data structures, how to sort arrays, all those useful things that aren't really in my wheelhouse at the moment lol
still, i'd rather that then ever write another line of css
Kaz Baig
@kbaig
Mar 30 2018 19:43
CSS <3
Kyle Holm
@thekholm80
Mar 30 2018 19:44
lol
Christopher McCormack
@cmccormack
Mar 30 2018 19:45
I write all my CSS in JS now :)
Kyle Holm
@thekholm80
Mar 30 2018 19:45
that's like hiding the broccoli in cheese, i still don't want to eat it
Christopher McCormack
@cmccormack
Mar 30 2018 19:45
haha
it's still regular CSS for the most part but you get to use variables and never have scoping issues
Kyle Holm
@thekholm80
Mar 30 2018 19:46
i did like scss better than plain css, but it's still putting lipstick on the pig
Kaz Baig
@kbaig
Mar 30 2018 19:47
I prefer to use Sass
Kyle Holm
@thekholm80
Mar 30 2018 19:47
are you one of those weird PUG guys too?
Kaz Baig
@kbaig
Mar 30 2018 19:47
mhmmmm
If I have to write plain html yes
My early days were watching Travis Neilson so I have to
Kyle Holm
@thekholm80
Mar 30 2018 19:48
my biggest complaint about python is lack of brackets ... using whitespace to define codeblocks is an abomination
almost as bad as the people who do
const myFunc = () => 
{
// ...
}
Kaz Baig
@kbaig
Mar 30 2018 19:50
But...why
Kyle Holm
@thekholm80
Mar 30 2018 19:50
when i first started python i was going through codeacademy's lessons, i spent more time fighting their online text editor thingy because it thought my indentation was wrong than i did learning
fortunately, switching to vs code solved all of that
Christopher McCormack
@cmccormack
Mar 30 2018 19:51
I disagree Python is perfectly readable without brackets
Kaz Baig
@kbaig
Mar 30 2018 19:51
First thing I do when advising people who want to start learning to code is to avoid codeacademy
Christopher McCormack
@cmccormack
Mar 30 2018 19:52
@kbaig agreed
Kaz Baig
@kbaig
Mar 30 2018 19:52
Often times it's the only place they've gone too
Manish Giri
@Manish-Giri
Mar 30 2018 19:54
What’s wrong with codeacademy
Christopher McCormack
@cmccormack
Mar 30 2018 19:55
@Manish-Giri last time I used it the structure of it wasn't very conducive to learning - it taught the basics but it felt very shallow after that
Better to learn with something that jumps you into projects right after covering the basics
Manish Giri
@Manish-Giri
Mar 30 2018 19:56
@cmccormack it's intended as a course that sets up the very basics (not beyond that), which is why it's especially suited for beginners
Christopher McCormack
@cmccormack
Mar 30 2018 19:58
There are many good resources that do that though
Kyle Holm
@thekholm80
Mar 30 2018 19:58
codeacademy got me through the basics, so i was happy. I just wanted to get the basic syntax down, from there it was off to the docs
Manish Giri
@Manish-Giri
Mar 30 2018 20:00
the way codeacademy has lessons, challenges, slides, pdfs, resources to external links while at the same time maintaining correct info (unlike w3schools), not a lot of other resources has that
Kaz Baig
@kbaig
Mar 30 2018 20:03
@Manish-Giri In my experience, which is using it to learn SQL, units that lead into each other also tend to not be consistent. For SQL, one module used a completely different shorthand convention than the other, and also used syntactic sugar I hadn't seen before. I think this is because they're actually getting companies to create units independently of each other in exchange for being listed as a sponsor
Kyle Holm
@thekholm80
Mar 30 2018 20:03
that sounds annoying
Christopher McCormack
@cmccormack
Mar 30 2018 20:04
@Manish-Giri I will admit i may have gotten better since the last time I used it. They have had a lot of time to improve
Manish Giri
@Manish-Giri
Mar 30 2018 20:06
@kbaig okay, I can't say about SQL, i've never touched sql in codeacademy..
Kaz Baig
@kbaig
Mar 30 2018 20:06
I also tried JS like a year before that and didn't retain anything even the next day
Could just be because I'm a dummy tho
Manish Giri
@Manish-Giri
Mar 30 2018 20:07
I learnt React first up from codeacademy, and I found it much better than what FCC currently has on surge
Kaz Baig
@kbaig
Mar 30 2018 20:09
I'll def check it out, been feeling like I need to get better at my React fundamentals recently. I keep refactoring the way I've implemented things. @Manish-Giri thanks for the recommendation
CamperBot
@camperbot
Mar 30 2018 20:09
kbaig sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6823 | @manish-giri |http://www.freecodecamp.org/manish-giri
Manish Giri
@Manish-Giri
Mar 30 2018 20:09
:+1:
Eunice Park
@eunicode
Mar 30 2018 20:37

Hello all, I guess my javascript is rusty bc I'm stuck on what's wrong with my code. I would really appreciate some help!

It's the Drop It challenge https://www.freecodecamp.org/challenges/drop-it
Drop the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true.
The second argument, func, is a function you'll use to test the first elements of the array to decide if you should drop it or not.
Return the rest of the array, otherwise return an empty array.

function dropElements(arr, func) {
  // Drop them elements.
  const filteredArr = arr.filter(func);
  const index = filteredArr[0];

  if (index) {
    return [];
  } else {
    const droppedArr = arr.slice(index);
    return droppedArr;
  }

}

dropElements([1, 2, 3], function(n) {return n < 3; });
Aditya
@ezioda004
Mar 30 2018 20:47
@eunipa Is this if (index) condition suppose to be like this? Because it'll always evaluate to true unless the index is 0 or any other falsy value.
Christopher McCormack
@cmccormack
Mar 30 2018 20:48
@eunipa do you mean to use map instead of filter?
> [1,2,3].map(n => n < 3)
[ true, true, false ]
> [1,2,3].filter(n => n < 3)
[ 1, 2 ]
Aditya
@ezioda004
Mar 30 2018 20:49

Drop the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true.

.filter() is a bad idea because it'll remove further even after it returns true for any element

Eunice Park
@eunicode
Mar 30 2018 20:52
@ezioda004 Thanks for replying. This is what I'm trying to do: If there are no elements in the array that pass the filter function test, then an empty array would be returned. And then the [][0] would return undefined. And undefined is falsy.
CamperBot
@camperbot
Mar 30 2018 20:52
eunipa sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
:cookie: 518 | @ezioda004 |http://www.freecodecamp.org/ezioda004
Aditya
@ezioda004
Mar 30 2018 20:55
@eunipa So do if (!index)? Since its a falsy value you'll want to return this condition to be true and return an empty array.
Eunice Park
@eunicode
Mar 30 2018 20:55
@cmccormack Thanks, I've tried substituting with map, but I still fail all the tests. I'll continue investigating
CamperBot
@camperbot
Mar 30 2018 20:55
eunipa sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1386 | @cmccormack |http://www.freecodecamp.org/cmccormack
Eunice Park
@eunicode
Mar 30 2018 20:56
@ezioda004 Wow, you're right! /facepalm
Christopher McCormack
@cmccormack
Mar 30 2018 20:56
@eunipa you'll still have to validate your code, put log statements in so you can see what your arrays look like at each step
@ezioda004 not if the first value is 0 and that's true in the context of the callback function
@eunipa just use if (!filteredArr.length > 0) {
personally I would implicitly return the empty array in the else, though
or even outside the conditional if the conditional returns something
Aditya
@ezioda004
Mar 30 2018 21:00
@cmccormack True, it was for undefined but yeah would be problematic for 0.
@eunipa arr.slice(arr.indexOf(index)); this fixes your code, you had only index passed into slice.
Eunice Park
@eunicode
Mar 30 2018 21:04
@ezioda004 Thank you so much! It took me a while to see why index wasn't the index, but I realize I needed to get the index of index. Thanks again for letting me see the light and catch my mistake!
CamperBot
@camperbot
Mar 30 2018 21:04
api offline
eunipa sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
Aditya
@ezioda004
Mar 30 2018 21:06
@eunipa :thumbsup:
A small nitpick you're initializing const droppedArr just to return it the next line. You should just return the sliced array instead of assigning to the variable.
Eunice Park
@eunicode
Mar 30 2018 21:09
@ezioda004 That's a good point, I guess I should always be thinking about memory? I don't know what the best practices are. I was just thinking of making the code super readable and easy to understand.
Christopher McCormack
@cmccormack
Mar 30 2018 21:11
@eunipa not memory really more like how do you PREVENT errors in the future. having two lines to do one thing means you can make a mistake in two places now
Eunice Park
@eunicode
Mar 30 2018 21:12
@cmccormack Alrighty! I guess there was a good reason why most people write their code that way :)
Christopher McCormack
@cmccormack
Mar 30 2018 21:13
@eunipa keep it concise!
Aditya
@ezioda004
Mar 30 2018 21:13
@eunipa Understood, I think its more or less just a good programming practice. If you're initializing a variable and going to return that without making any other use of it, you can refactor your code and not use that variable in the first place.
Eunice Park
@eunicode
Mar 30 2018 21:15
@ezioda004 :ok_hand: I'll do it this way from now on.