Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 17:13
    @mstellaluna banned @cmal
  • Jan 08 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
  • Jul 29 2018 01:00
    @bjorno43 banned @jkyereh
  • Jul 10 2018 22:09
    @bjorno43 banned @manafn
  • Jul 06 2018 15:20
    @texas2010 banned @imlegend19
  • Jul 03 2018 12:28
    @bjorno43 banned @vbvmatta
  • Jun 29 2018 13:54
    @bjorno43 banned @OGTechnoBoy
Thomas Tylek
@zippkidd
@moT01 but they probably should. from stack overflow: "The problem with writing scripts at the head of a page is blocking. The browser must stop processing the page until the script is download, parsed and executed. The reason for this is pretty clear, these scripts might insert more into the page changing the result of the rendering, they also may remove things that dont need to be rendered, etc. "
@g4m3rm1k3 you're doing fine. The important thing is you're learning! Good for you!
Tom
@moT01
what happens if you want a script loaded before the rest of the stuff
Michael
@g4m3rm1k3
is there like an onload function?
Tom
@moT01
@g4m3rm1k3 yes
Thomas Tylek
@zippkidd
@moT01 in that case you load in the script at that specific point, and no sooner. Obviously this is a flexible rule and if there is a case where you need to load the script before the </body> then you would do that
It's just generally considered good practice to load mostly all scripts right before </body>
TonyRednil
@TonyRednil
Can the .replace function be called on a number in an array?
Moisés Man
@moigithub
replace works for strings... soo u need to convert it to string if u wanna use
TonyRednil
@TonyRednil
@moigithub Yeah, I don't think there are enough values in the array to do that. I've been trying to use the .filter function and it keeps telling me "false is not a funciton" or "2 is not a function".

function destroyer(arr) {
var args = Array.prototype.slice.call(arguments);
args = args.slice(1);
for (var i = 0; i < args.length; i++) {
for (var j = 0; j < arr.length; j++) {
Array.prototype.filter(arr[j] < args[i]);
}
}
return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

Thomas Tylek
@zippkidd
@moigithub I don't think you should be using array.prototype...
shouldn't you be using arr there, the parameter of the function?
TonyRednil
@TonyRednil
I've just been attempting to follow what the guide is instructing me to use. The parameter of the function is to remove the arguments from the array. So the code I posted should return [1, 1]
I tried just simply doing return arr.filter(arguments); but that returned "2 is not a function"
Moisés Man
@moigithub
Thomas Tylek
@zippkidd
Try to use Array.from your arguments object, then slice it
TonyRednil
@TonyRednil
@moigithub Yeah, I have been reading that over and over and can't seem to get a function where it will return the values that pass it. I've tried: arr.filter(arr[i] === args[j]); arr.filter(arr[i] == args[j]); arr.filter(arr[i] >= args[j]); arr.filter(arr[i] <= args[j]); etc and they all return something like "true is not a function" "false is not a function" "2 is not a function" "array is not a function". Do I need to do something like arr.filter(arr = arr[i] < args[j]);?
Thomas Tylek
@zippkidd
so, var args = Array.from(arguments).slice(1)
Moisés Man
@moigithub
arr[i] <= args[j] is not a function/callback
u need to pass a function to filter
TonyRednil
@TonyRednil
@zippkidd Is that even necessary if arr calls the array that is in the arguments?
@TonyRednil Then I'm totally lost as to what an function would be to pass through that.
@moigithub Then I'm totally lost as to what a function would be to pass through that.
Moisés Man
@moigithub

example...

function even(num){ return num % 2 === 0; }
[1,2,3,4].filter(even)

as u can see.. even is a function.. which accepts some parameters
filter callback function.. have some parameters predefined.. but most of time only first one is used
filter will take each values from the array.. one by one.. and call the function with that value...
and return only the values which evaluates as true

TonyRednil
@TonyRednil
So that function would filter values that have an odd remainder when divided by 2?
Thomas Tylek
@zippkidd
@TonyRednil no it's not necessary, what you're doing works. I would at least remove Array.prototype and replace it with just arr, but maybe that's just my personal preference
@TonyRednil in regards to @moigithub 's example, think about what's going on with the return value
when 1 is passed in as num, is 1 % 2 === 0?
no, so false is being returned.
and as stated by in the MDN filter link: "Return true to keep the element, false otherwise..."
Thomas Tylek
@zippkidd
@TonyRednil so yes, that function removes values that have any remainder after the remainder 2 operation is done. Reminder, % is not division, it is the remainder operator
Your filter method may be more complicated though because the test cases have arguments that are strings too
TonyRednil
@TonyRednil
And I was hoping to keep this code simple....
Thomas Tylek
@zippkidd
I would recommend something like return arr.filter(function(element) { return !args.includes(element)}
so ultimately between that and separating the arguments into an array to alter and the arguments to check the array against, it's only a few lines of code
TonyRednil
@TonyRednil
So that is going to ultimately return arr with only values that aren't equal to either argument? What is element? Is that just a way to call each individual value in the array?
Thomas Tylek
@zippkidd
filter runs through each element of the array you called it on
TonyRednil
@TonyRednil
So then what is element?
Thomas Tylek
@zippkidd
element can be renamed to anything, but essentially element is first arr[0], then arr[1], and so on...
TonyRednil
@TonyRednil
Ah gotcha. So that code you posted is going to check each value in arr and if it's equal to either value in args it will remove it and return everything else? Am I understanding that right?
I'm still new to the while includes method
Whole*
Thomas Tylek
@zippkidd
Yup. Because it goes, "Oh lets filter. We're filtering arr, so let's start with arr[0]. arr[0] is 1. Okay, so let's run value one into the callback function (what's inside filter(...))
"okay, the callback runs. 1 is used as the value in that function (element)."
"the callback wants to know if !args.includes(element), so does the args array NOT include this element (1)?"
TonyRednil
@TonyRednil
Do I need to declare anything I set in place of where you put "element"?
Thomas Tylek
@zippkidd
no, it's implicitly being declared.
just as function foo(a) {return a;} doesn't need a to be declared
TonyRednil
@TonyRednil
I clearly have much to learn.