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
Sweet Coding :)
@SweetCodingInc
@Masd925 :+1:
that prototype one looks clean
Joshua Frias
@Juke-Magic
guys how do i add \n in here?
result = result + [i] + ", ";
Amit Patel
@AmitP88

hey all, I'm stuck on yet another algorithm - Return Largest Numbers in Array. Here's my code so far:


function largestOfFour(arr) {
  // You can do this!






  var maxArr = arr.map(function(max) {

      for (var i = 0; i < arr.length; i++) {    


           return Math.max.apply(null, arr[i]); 

      }


  });            


      return maxArr;


//        return Math.max.apply(null, arr[0]);     







}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

I understand that this code outputs [5,5,5,5], which is the highest element of the first sub-array. But, I'm having trouble figuring out how my for loop should be. I've tried making a nested for loop using i and j, but that didn't work either.

Markus Kiili
@Masd925
@Juke-Magic Adding a string and an array is not a good idea.
@AmitP88 arr.map... already loops arr elements. No need for that for loop.
Marianissimus
@Marianissimus
@AmitP88 you tell it: for every item of the bigarray (so all 4 sub-arrays), return the largest in the first subarray - arr[i], which it does
Joshua Frias
@Juke-Magic
@Masd925 yep its just for testing stuff
how to i create a line break though?
here is the pen
Marianissimus
@Marianissimus
you return it too soon, it doesn't get the chance to loop through all the subarrays @AmitP88
Amit Patel
@AmitP88
@Marianissimus so I should put my return statement outside the loop?
Markus Kiili
@Masd925
@AmitP88 Better to name it like arr.map(function(innerArray) { so you see that that parameter holds each inner array in its turn.
And just return the largest number of array innerArray from that map callback.
Marianissimus
@Marianissimus
@AmitP88 yes, outside the loop. maybe use the results for each subarray and create a new one? I dont know...
Amit Patel
@AmitP88
@Marianissimus I was thinking of doing that, but wouldn't that break the DRY rule?
Marianissimus
@Marianissimus
why? what are you repeating? you need to return an array, dont you?
Amit Patel
@AmitP88
oh, I thought you meant like:
math.max.apply(null, arr[0]
math.max.apply(null, arr[1]
etc
Marianissimus
@Marianissimus
or use the map/reduce function. it's shorter, of course
Markus Kiili
@Masd925
@AmitP88 You just need to map element arrays to maximum elements of those arrays. So map is a good idea.
Marianissimus
@Marianissimus
@AmitP88 oh, no. use the loop, just dont return the results, use them in a new array;
push them into newarr, for instance
Amit Patel
@AmitP88
ah I see
Joshua Frias
@Juke-Magic
guys help me please
i need ya'll
Amit Patel
@AmitP88
ok, I'll brb. gotta sort this out real quick. thanks @Marianissimus @Masd925 for your tips. I'll let you know how it goes :)
CamperBot
@camperbot
amitp88 sends brownie points to @marianissimus and @masd925 :sparkles: :thumbsup: :sparkles:
:cookie: 456 | @marianissimus |http://www.freecodecamp.org/marianissimus
:star2: 4657 | @masd925 |http://www.freecodecamp.org/masd925
Markus Kiili
@Masd925
@AmitP88 Easiest is to forget the loop and just use map and Math.max.
Amit Patel
@AmitP88
@Masd925 for sure. I'll see if I can pull it off using just those two methods. I think I'm overdoing it with the loop
Ayush Bahuguna
@relentless-coder
can anyone help me with react?

this is my component

export function AllExpense(props) {
    const renderExpense = ({data}) => {
        console.log(data.data);
        return (
            <div>
                <div>
                    <h2><Link to="/expense/new">Add Expense</Link></h2>
                </div>
                {
                    data.data.length > 0 ? <ul>
                        <li>
                            data.data.map(el =><ListItem key={el._id.toString()} value={el}/>)
                        </li>
                    </ul> : <h2>Enter some data!!</h2>
                }

            </div>
        )
    };
    return allExpenseAPi().then(renderExpense).catch((err) => {
        alert(err.message)
    })
}

and I keep getting error Objects are not valid as a React child

William Watts
@Braillon7
hello campers...I'm in dire need of help on something that could turn out to be very simple...I'm working on the second page of my "todoapp" and for some reason I can't get my, short, Jquery function to work..it's just a short statement to bring up a css class instruction https://codepen.io/Braillon7/pen/RxBWbY
Anshul Adlakha
@anshuladlakha
I'm trying to make a new tab chrome extension and I'm trying to add a clock to it and I'm having a really hard time because Chrome won't let me load setIntervals which I need for updating the time every second, then I tried using chrome alarms API by adding a event page but for some reason that's not working either. Can anyone help me out.
Ayush Bahuguna
@relentless-coder
okay, i resolved it, nevermind
William Watts
@Braillon7
@AmitP88 were you able to figure it out?
Joy
@Yorokobi05
Hello, I would just like to ask if the challenge for the Falsy Bouncer under the Basic Algorithm cannot be solved by using Microsoft Edge. (Am I really required to use Mozilla for this?) Thanks.
VaseJS
@VaseJS
@Yorokobi05 maybe just not microsoft Edge
Joy
@Yorokobi05
ok, thanks. I'll try again. :)
Tom
@moT01
@Braillon7 any luck? what are you trying to do? - you add the active class but there's no style for it
ehutchllew
@ehutchllew
@Braillon7 the event handler is working, but your task-form element seems to be hidden, at least on my screen.
@relentless-coder if you need further help with react, let me know, I work with it daily hehe.
Emil
@aguyinmontreal
Hi everyone! Does someone knows how jquery ajax exactly determines what is a "fail" in $.ajax.fail ? I can't find the documentation for it :/
Omar Tan
@wheelhot

Woo hoo! Finally completed Twitch.tv project!

https://codepen.io/wheelhot/full/XVxyEK/

Oddly there’s some weird scaling behaviour on codepen, I don’t get this issue on the various browsers I tested

ehutchllew
@ehutchllew
@aguyinmontreal been a while since i've used jQuery's ajax call, but isn't there an "error" parameter when you fill out the request object?
Kaz Baig
@kbaig

@aguyinmontreal From the jquery.ajax documentation:

jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
An alternative construct to the error callback option, the .fail() method replaces the deprecated .error() method. Refer to deferred.fail() for implementation details.

The jqXHR objects returned by $.ajax()