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
Amit Patel
@AmitP88
@eweiss17 I think so. But I also tried using the map method in the for loop to avoid this, but then I run into errors
Ayush Bahuguna
@relentless-coder
@AmitP88 also, you have used map incorrectly, in case you are still fixated at using map to solve your problem
Eric Weiss
@eweiss17
the result is a new array with the max values?
Amit Patel
@AmitP88

@relentless-coder in the loop, I don't think it is. But, if I just had the maxElement variable alone, and use this instead:

var maxElement = Math.max.apply(null, arr[0]);

then it returns the highest element in the first sub-array

Eric Weiss
@eweiss17
can you just push the highest values on an array if map is giving problems
Amit Patel
@AmitP88
@eweiss17 yup, that's the goal at least
I was just thinking of that actually. just creating a new variable set to an empty array, then use .push to place the elements in
Ayush Bahuguna
@relentless-coder
@AmitP88 pull the maxElement outside your second loop, then after the second loop push the maxElement into an array
Kaz Baig
@kbaig
This would be a relatively simple one liner solution
Nick
@rhozeta
can anyone help with jQuery animation
Ayush Bahuguna
@relentless-coder
@kbaig can you share? I have been working towards learning algorithms and datastructures, and I am sure your code could be a part of my arsenal.
Nick
@rhozeta
$(document).ready(function(){

var $truck = $('#truck')


$truck.click(function (){

    $truck.animate({right: "300px"});
});

});
however when clicking no animation occurs
Kaz Baig
@kbaig
to return an array that contains max of each subarray
function largestOfEach(arr) {
  return arr.map(subArr => Math.max(...subArr));
}
Ayush Bahuguna
@relentless-coder
@rhozeta right property doesn't work with static DOM elements
Muhammed Hafiz
@zifahm
Could anyone tell me why is this not rendering
https://codepen.io/m_zifah/pen/MrPZZO?editors=0011
console doesnt give any errors, i tried without the map and it works fine
Kaz Baig
@kbaig
@relentless-coder ^
Ayush Bahuguna
@relentless-coder
@kbaig what would you say is the complexity of your solution?
Amit Patel
@AmitP88

@relentless-coder


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



  // loop through all the sub-arrays
  for(var i = 0; i < arr.length; i++) {
    for(var j = 0; j < arr[i].length; j++) {
         var newArray = [];
          newArray.push(maxElement);

      return newArray;       
    }

       var maxElement = Math.max.apply(null, arr[i]);


  }




}

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

Hmm, I'm doing something wrong :(

Nick
@rhozeta
@relentless-coder what would be my option for animating that then?
Emil
@aguyinmontreal
@kbaig Thank you so much!! I don't know why I didn't find this myself when I looked on stackoverflow!
CamperBot
@camperbot
aguyinmontreal sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
api offline
Eric Weiss
@eweiss17
@AmitP88 i got a solution using your method, ditch the j loop and go from there
Emil
@aguyinmontreal
@relentless-coder kbaig found the issue ;) (for my issue, sorry to interrupt) https://stackoverflow.com/questions/6186770/ajax-request-returns-200-ok-but-an-error-event-is-fired-instead-of-success
Toni Shortsleeve
@KoniKodes
@zifahm Try changing document.getElementById to document.querySelector
Ayush Bahuguna
@relentless-coder
@aguyinmontreal told you that it was highly probable that promise was throwing error
Emil
@aguyinmontreal
@relentless-coder thanks
CamperBot
@camperbot
aguyinmontreal sends brownie points to @relentless-coder :sparkles: :thumbsup: :sparkles:
:cookie: 385 | @relentless-coder |http://www.freecodecamp.org/relentless-coder
Amit Patel
@AmitP88

@eweiss17


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



  // loop through all the sub-arrays
  for(var i = 0; i < arr.length; i++) {

       var maxElement = Math.max.apply(null, arr[i]);  
       var newArray = [];
       newArray.push(maxElement);

      return newArray;     
  }




}

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

Here's what I did after ditching the j loop like you suggested

Nick
@rhozeta
@relentless-coder how would I go about animating that static element?
ehutchllew
@ehutchllew
@zifahm not familiar with panel group but have you tried adding any styling?
Ayush Bahuguna
@relentless-coder
@rhozeta translate
Eric Weiss
@eweiss17
did it work?
Muhammed Hafiz
@zifahm
@KoniKodes nope no change
Amit Patel
@AmitP88
@eweiss17 the output now is [5]
Ayush Bahuguna
@relentless-coder
@rhozeta i mean the translate3d
Muhammed Hafiz
@zifahm
@ehutchllew when i try without the map func it works fine
Eric Weiss
@eweiss17
return newArray outside of the for loop
Nick
@rhozeta
@relentless-coder so I would have to use #truck.css({translate3d: x,x,x });
Amit Patel
@AmitP88
@eweiss17 now I get [1001]
Ayush Bahuguna
@relentless-coder
ehutchllew
@ehutchllew
@zifahm try defining your state inside the constructor:
constructor(){
super();
this.state = {}
}
Amit Patel
@AmitP88
@eweiss17 it also says that return newArray is out of scope
Muhammed Hafiz
@zifahm
@ehutchllew i tried that too
Ayush Bahuguna
@relentless-coder
@rhozeta I am sorry if this going to sound rude, but kindly look up translate3d property on Google, and take it from there :)
ehutchllew
@ehutchllew
@zifahm remove the logic from the render method, create your own class methods and then render based off of their output.
Amit Patel
@AmitP88
@eweiss17 just solved it by moving var newArray=[] outside of scope
Ayush Bahuguna
@relentless-coder
@AmitP88 why are you so obsessed with the correct solution? Instead think of your approach