These are chat archives for FreeCodeCamp/HelpJavaScript

13th
Jan 2018
DistinctWolf
@DistinctWolf
Jan 13 2018 02:38
If a user gets the sequence of clicks wrong, then do i start from the beginning or at a random sequence because the freecodecamp user story says I can play in strict mode where if I get a button press wrong, it notifies me that I have done so, and the game restarts at a new random series of button presses. ,but in their example game sequence resets, what am i supposed to do ?
Kaz Baig
@kbaig
Jan 13 2018 02:59
@FlashHero they mean the game starts from the beginning with a new sequence
Rohit Yadav
@rohyadav
Jan 13 2018 03:59
const tripList = [
    {
        id: 0,
        title: 'spain',
        url: '/destination/spain',
        arrive: '',
        departure: '',
        visited: false,
        cities: [
            {
                id: 0,
                title: 'madrid',
                arrive: '',
                departure: ''
            },
            {
                id: 1,
                title: 'barcelona',
                arrive: '',
                departure: ''
            },
            {
                id: 2,
                title: 'ibiza',
                arrive: '',
                departure: ''
            }
        ]
    },
    {
        id: 1,
        title: 'italy',
        url: '/destination/italy',
        arrive: '',
        departure: '',
        visited: false,
        cities: [
            {
                id: 0,
                title: 'belluno',
                arrive: '',
                departure: '',
                attractions: [
                    {
                        id: 0,
                        title: 'dolomitas'
                    }
                ]
            },
            {
                id: 1,
                title: 'veneza',
                arrive: '',
                departure: ''
            }
        ]
    }
];

const list = tripList.map((list, key)=> {
                      return (
                        Object.keys(list).map((l, k)=> {
                          return (
                            <li key={k}>{list.cities}</li>
                          )
                        })
                      )

                  })
I am trying to get the values of attractions? anyone help me out
using map
DistinctWolf
@DistinctWolf
Jan 13 2018 04:45
@kbaig ok thanks
CamperBot
@camperbot
Jan 13 2018 04:45
flashhero sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 523 | @kbaig |http://www.freecodecamp.org/kbaig
DistinctWolf
@DistinctWolf
Jan 13 2018 04:58
@rohyadav You can access the attractions values using tripList[1].cities[0].attractions, but this will not work if you have to get values for all the objects or array
Rohit Yadav
@rohyadav
Jan 13 2018 05:09
@FlashHero thanks, but if i get values for all the objects or array then whats need to done
CamperBot
@camperbot
Jan 13 2018 05:09
rohyadav sends brownie points to @flashhero :sparkles: :thumbsup: :sparkles:
:cookie: 239 | @flashhero |http://www.freecodecamp.org/flashhero
Pieter Stokkink
@forkerino
Jan 13 2018 07:54
@rohyadav you can use a .map like you did, or a .reduce, but you need to make sure the property exists as well. Some cities don't have an attractions prop, so you need to make sure that they have one before you do something like attractions.map(...) Otherwise you'll get .map is not a function errors.
Ene Catalin
@EneCatalin
Jan 13 2018 07:56
guys any idea how I can send a bunch of photos to an url in js ? I mean 10+ photos
Pieter Stokkink
@forkerino
Jan 13 2018 08:05
@EneCatalin using a form in a frontend? Or....?
Ene Catalin
@EneCatalin
Jan 13 2018 08:06
ideally yes
I pretty much need the user to select photos from the pc then they get sent over to an url
I need to get this done in a couple hours. If it's not doable in js I am willing to try to do it in php (but I've never really touched the language), I just to find a way to do it in about 24h
also I obv do not care about security at this point, so any simple solution is perfect
Pieter Stokkink
@forkerino
Jan 13 2018 08:12
would you also need to do the server-side?
Rohit Yadav
@rohyadav
Jan 13 2018 11:28
@forkerino thanks man :+1:
CamperBot
@camperbot
Jan 13 2018 11:28
rohyadav sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2963 | @forkerino |http://www.freecodecamp.org/forkerino
Rohit Yadav
@rohyadav
Jan 13 2018 11:29
@forkerino got solution how about this
// Get All Cities
        let cities = tripList.map(list => {
            return list.cities
        })

        // Flatten the arrays
        cities = [].concat.apply([], cities)

              // Get all cities attractions
              let aca = cities.filter(city => city.attractions)

        // Get all attractions => [Array(1), Array(1), Array(1)]
        let aa = aca.map(c=>{
            return c.attractions
        })
        console.log(aa)

        // Flatten the arrays => [object Object],[object Object],[object Object]
        let attractions = [].concat.apply([], aa)
        console.log("spread arrays into one array: " + attractions)

        // Get all the attraction titles
        let atitle = attractions.map(r=> {
            return console.log(r.title)
        })
any suggestion
Pieter Stokkink
@forkerino
Jan 13 2018 11:35
@rohyadav does this work properly?
We can probably simplify this code by using a .reduce (you can for example almost always combine a map and filter into one reduce)
It really depends on what output you want
BTW, since you are using ES6 arrow functions, you might as well use the spread operator to flatten the arrays.
[].concat(...cities)
Rohit Yadav
@rohyadav
Jan 13 2018 11:42
@forkerino thank you, yes like this yup it's working
CamperBot
@camperbot
Jan 13 2018 11:42
rohyadav sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
api offline
Rohit Yadav
@rohyadav
Jan 13 2018 11:42
// Get All Cities
        let cities = tripList.map(list => {
            return list.cities
        })

        // Flatten the arrays oldway-  cities = [].concat.apply([], cities)
              cities = [].concat(...cities)

              // Get all cities attractions
              let aca = cities.filter(city => city.attractions)

        // Get all attractions => [Array(1), Array(1), Array(1)]
        let aa = aca.map(c=>{
            return c.attractions
        })
        console.log(aa)

        // Flatten the arrays => [object Object],[object Object],[object Object]
        let attractions = [].concat(...aa)
        console.log("spread arrays into one array: " + attractions)

        // Get all the attraction titles
        let atitle = attractions.map(r=> {
            return console.log(r.title)
        })
could you please update this code using reduce method, that will really help me to understand how'z the implementation
Pieter Stokkink
@forkerino
Jan 13 2018 11:57
do you need just the titles of the attractions?
@rohyadav
I think in any case you will have to combine things, because of how nested the datastructure is.
Rohit Yadav
@rohyadav
Jan 13 2018 12:03
yes, for now i am just learning things no matter how complex json data
Pieter Stokkink
@forkerino
Jan 13 2018 12:03
let me think for a second
Rohit Yadav
@rohyadav
Jan 13 2018 12:03
but i am not sure if it is right way or there is another better way to do it
Pieter Stokkink
@forkerino
Jan 13 2018 12:09

how about:

let titles = tripList.reduce((result, list) => {
  let attractions =  list.cities.reduce((result, city) => {
    return city.attractions ? result.concat(city.attractions.map(attraction => attraction.title)) : result
  }, [])
  return attractions.length ? result.concat(attractions) : result
}, [])

slightly shorter, but maybe harder to grok for people with less experience coding.

But it should return an array of all attractions.
Actually that second ternary is unnecessary, this works too:
let titles = tripList.reduce((result, list) => {
  let attractions =  list.cities.reduce((result, city) => {
    return city.attractions ? result.concat(city.attractions.map(attraction => attraction.title)) : result
  }, [])
  return result.concat(attractions)
}, [])
Rohit Yadav
@rohyadav
Jan 13 2018 12:15
can you please write some comment on lines so that easy understand for me
Stephen James
@sjames1958gm
Jan 13 2018 12:18
@forkerino maybe use different names than result to clarify what result holds?
Pieter Stokkink
@forkerino
Jan 13 2018 12:19
let titles = tripList.reduce((allTitles, list) => { // take each list 
  let attractions =  list.cities.reduce((attractionsForList, city) => { // take each city in the list
    // if the city has attractions, add (.concat) their titles (the .map) to the running result
    // otherwise return the running result 
    return city.attractions ? attractionsForList.concat(city.attractions.map(attraction => attraction.title)) : attractionsForList
  }, []) // start value for inner reduce is an empty array
  return allTitles.concat(attractions) // add the attractions to allTitles
}, []) // start value for outer reduce is an empty array
something like that
Stephen James
@sjames1958gm
Jan 13 2018 12:21
@forkerino :+1:
Rohit Yadav
@rohyadav
Jan 13 2018 12:21
@forkerino thank you so much, for giving valuable time ...
CamperBot
@camperbot
Jan 13 2018 12:21
rohyadav sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
api offline
Pieter Stokkink
@forkerino
Jan 13 2018 12:21
no problem
Rohit Yadav
@rohyadav
Jan 13 2018 12:22
var expObject = {
    name: 'Raymon',
    title: 'Lead Frontend/JavaScript Developer',
    yearsExperience: 8,
    projects: [
        {
            name: "Company A",
            title: 'Senior JavaScript Developer',
            techniques: ['Angular', 'ES6', 'Vanilla JavaScript', 'Less', 'CSS']
        },
        {
            name: "Company B",
            title: 'Lead JavaScript Developer',
            techniques: ['Angular 2', 'AngularJS', 'ES6', 'Vanilla JavaScript', 'Web Sockets', 'D3']
        },
        {
            name: "Company C",
            title: 'Senior Frontend Developer',
            techniques: ['Vanilla JavaScript', 'CSS', 'Responsive Webdesign']
        }
    ]
}

var eObj = Object.entries(expObject).map((item)=> {
    return console.log(item)
})

var fa = [].concat(...eObj)
console.log(fa)
Pieter Stokkink
@forkerino
Jan 13 2018 12:22
I would probably rename list to trip
Rohit Yadav
@rohyadav
Jan 13 2018 12:23
in another example
(2) ["name", "Raymon"]
 (2) ["title", "Lead Frontend/JavaScript Developer"]
(2) ["yearsExperience", 8]
(2) ["projects", Array(3)]
(4) [undefined, undefined, undefined, undefined]
got output
Pieter Stokkink
@forkerino
Jan 13 2018 12:25
yes
the console.log(item) returns undefined, so you'll get an array of undefineds
Rohit Yadav
@rohyadav
Jan 13 2018 12:26
oh
Pieter Stokkink
@forkerino
Jan 13 2018 12:27
if you get rid of the .map, you'll get the proper stuff in fa
probably
Rohit Yadav
@rohyadav
Jan 13 2018 12:30
no not
its should be come in one array so i can itterate
Pieter Stokkink
@forkerino
Jan 13 2018 12:33
how do you want the end result to look?
Rohit Yadav
@rohyadav
Jan 13 2018 12:37
company A -: techniques:- 
             angular
             es6
              .
              . 
company B -: techniques:- 
             angular 2
             AngularJS
              .
              . 
company C -: techniques:- 
             vanila JavaScript
             css
              .
              .
like so
Pieter Stokkink
@forkerino
Jan 13 2018 12:41
I suggest you .map over the projects array, because all the information you need is there.
Rohit Yadav
@rohyadav
Jan 13 2018 12:43
yes if i used .map is not a function errors
var obj = expObject.map(item=> item)
Pieter Stokkink
@forkerino
Jan 13 2018 12:50
@rohyadav use expObject.projects.map(...
Rohit Yadav
@rohyadav
Jan 13 2018 12:55
(5) ["Angular", "ES6", "Vanilla JavaScript", "Less", "CSS"]
(6) ["Angular 2", "AngularJS", "ES6", "Vanilla JavaScript", "Web Sockets", "D3"]
(3) ["Vanilla JavaScript", "CSS", "Responsive Webdesign"]
let obj = expObject.projects.map(item=> {
    console.log(item.techniques)
})
Pieter Stokkink
@forkerino
Jan 13 2018 14:14
okay, looks like you're on the right path
Rohit Yadav
@rohyadav
Jan 13 2018 14:50
@forkerino can you please suggest any tutorial or blogs or anything from that i get deeper understanding in js(es6) specially when it comes in programming i stuck
Kelechi Chinaka
@ke1echi
Jan 13 2018 15:08
how do i share a pic on gitter chat room?
Pieter Stokkink
@forkerino
Jan 13 2018 15:09
Kyle Simpsons' You don't know JS series is great. https://github.com/getify/You-Dont-Know-JS/ It's six books you can read online for free. Note that .map .reduce and .filter are already available from ES5. Another good resource (if you are into videos more) is funfunfunction on youtube
@rohyadav ^
@kelechy You can just drag and drop it here
Kelechi Chinaka
@ke1echi
Jan 13 2018 15:11
docker error.JPG
thanks @forkerino
CamperBot
@camperbot
Jan 13 2018 15:12
kelechy sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2965 | @forkerino |http://www.freecodecamp.org/forkerino
Kelechi Chinaka
@ke1echi
Jan 13 2018 15:12
i think docker is driving me nuts
Pieter Stokkink
@forkerino
Jan 13 2018 15:13
@kelechy That is a common thing, in the beginning
Kelechi Chinaka
@ke1echi
Jan 13 2018 15:13
i get that errors after close to an hour of download and it stops downloading.. i need help, what could be wrong? @forkerino
Pieter Stokkink
@forkerino
Jan 13 2018 15:20
I'm not entirely sure. TLS usually is some security issue. I got completely sick of using docker on my windows machine, so I switched to Ubuntu, which is really a breeze in comparison.
can you try docker-machine ssh default ?
@kelechy ^
Kelechi Chinaka
@ke1echi
Jan 13 2018 15:21
i really am sick of it @forkerino :worried:
what does it take to switch to ubuntu?
Pieter Stokkink
@forkerino
Jan 13 2018 15:22
you basically install ubuntu on a machine and run it. Running virtual machines on windows can be quite taxing for the machine, but on ubuntu it is a native capability. Docker needs far less setup on linux.
Just make sure you do a proper backup of important stuff before you install ubuntu.
Kelechi Chinaka
@ke1echi
Jan 13 2018 15:23
Capturedocker.JPG
result of that command
Pieter Stokkink
@forkerino
Jan 13 2018 15:23
can you type docker ps there
Kelechi Chinaka
@ke1echi
Jan 13 2018 15:24
i think i will need that switch.. been tryin to install cs50 ide ofr offline use for days now :worried: @forkerino
Pieter Stokkink
@forkerino
Jan 13 2018 15:25
awww, sounds frustrating.
Kelechi Chinaka
@ke1echi
Jan 13 2018 15:25
Capturedocker.JPG
Pieter Stokkink
@forkerino
Jan 13 2018 15:26
ok, so you don't have any containers running
@kelechy what command gave you the error?
Kelechi Chinaka
@ke1echi
Jan 13 2018 15:28
docker run --privileged -e "OFFLINE_IP=$(docker-machine ip default)" -e "OFFLINE_PORT=8080" --name ide50 -d -p 5050:5050 -p 8080-8082:8080-8082 cs50/ide50-offline
Pieter Stokkink
@forkerino
Jan 13 2018 15:35
the thing that looks a bit weird to me (although I have my docker instance set up and haven't needed to troubleshoot for months) is the two -p flags. But other than that I don't have any ideas apart from trying again.
@kelechy
Rohit Yadav
@rohyadav
Jan 13 2018 15:35
@forkerino thanks a lot :+1:
CamperBot
@camperbot
Jan 13 2018 15:35
rohyadav sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2966 | @forkerino |http://www.freecodecamp.org/forkerino
Pieter Stokkink
@forkerino
Jan 13 2018 15:39
you're welcome
Simon Davis
@Skidragon
Jan 13 2018 15:46
Hello everyone, I was wondering if using labels is bad practice for solving the Wherefore Art Thou problem.
'use strict';
function whatIsInAName(collection, source) {

  let arr = [];

  goToNextItemInCollection:
    for (let i = 0; i < collection.length; i++) {

      if (source.length>collection[i].length) {
        continue;
      }
      for (let key in source) {
        if (collection[i][key] !== source[key]) {
          continue goToNextItemInCollection;
        }
      }
      arr.push(collection[i]);
    }
  return arr;
}
Ken Haduch
@khaduch
Jan 13 2018 15:51
@Skidragon - it's not really necessary to use them, and I haven't seen anyone using them in a long time. I think that it's a generally accepted practice to not use "goto" type of construction in your code, at least from way back in the day. That feature is always available, though, and you could use it if necessary. But I don't know of many cases where it would be used?
Simon Davis
@Skidragon
Jan 13 2018 15:57
@khaduch Thanks, I've just seen it for the first time on javascript.info and it just seemed cleaner than the solutions posted on freecodecamp.
CamperBot
@camperbot
Jan 13 2018 15:57
skidragon sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3674 | @khaduch |http://www.freecodecamp.org/khaduch
Ken Haduch
@khaduch
Jan 13 2018 16:03

@Skidragon - well, I'll offer my first attempt at this, and then show a second attempt using higher-order functions. My first attempt was my "brute-force" idea of counting things that matched and didn't match and making the decision based on that. Here is is:

function whatIsInAName_ORIGINAL(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  var sourceKeys = Object.keys(source);
  for ( var i = 0; i < collection.length; i++) {
    var matches = 0,
        misses = 0;
    for ( var j = 0; j < sourceKeys.length; j++ ) {
      if (collection[i].hasOwnProperty(sourceKeys[j]) &&
         collection[i][sourceKeys[j]] === source[sourceKeys[j]]) {
        matches++; // count the number of matches
      } else {
        misses++; // count the number of misses
      }
    }
    if ( matches && !misses ){
      arr.push(collection[i]); // had some matches and no misses, save it!
    }
  }
  // Only change code above this line
  return arr;
}

So i found no need to jump out of the loop at any point, although it might have been efficient to do that upon finding a "miss" in the comparison.
The second attempt, using higher-order functions, was a lot cleaner. (I wasn't really too much into using those at first, so after learning more about them it was fun to retry the solution). Second attempt:

function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line

  var sourceKeys = Object.keys(source);
  arr = collection.filter(function(item, i, col) {
    return sourceKeys.every( function(key, ii){
      return item.hasOwnProperty(key) && item[key] === source[key];
    });
  });
  // Only change code above this line
  return arr;
}

And of course I'm not saying that this is the ultimate solution - I could probably cut a couple more lines out by directly returning from the filter method, for example. It just shows a couple possibilities. I could probably rework this with ES6 arrow functions, and that would make it more concise. I had not been exposed to the ES6 stuff at that point...

@Skidragon - if you look at this documentation page: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label on MDN, it has a note:

Labeled loops or blocks are very uncommon. Oftentimes function calls can be used instead of loop jumps.

Which I could concur with.

Pieter Stokkink
@forkerino
Jan 13 2018 16:13
@khaduch :wave:
The .hasOwnProperty() isn't even necessary, because when they are not there, they can't be equal to a key on source, unless that key is also undefined. I ultimately did it this way:
const whatIsInAName = (coll, src) => coll.filter(obj => Object.keys(src).every(key => obj[key] === src[key]))
Ken Haduch
@khaduch
Jan 13 2018 16:18
@forkerino - hello and thank you for the comment! I'm frequently confused about the use (or non-use) of .hasOwnProperty() because (and possibly due to the way that I've structured code) I get errors about property values not existing or something like that. I don't have a ready example...
CamperBot
@camperbot
Jan 13 2018 16:18
khaduch sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2967 | @forkerino |http://www.freecodecamp.org/forkerino
Pieter Stokkink
@forkerino
Jan 13 2018 16:20
@khaduch I think those cases usually involve accessing a subproperty on the property you test.
Simon Davis
@Skidragon
Jan 13 2018 16:52
Search and Replace Exercise
Any reason why this does not work as a solution?
"use strict";
const isFirstLetterUpperCase = str => str[0] === str[0].toUpperCase();

function myReplace(str, before, after) {

  if(isFirstLetterUpperCase(before)===true) {
     after = after[0].toUpperCase() + after.slice(1);
  }
  return str.replace(new RegExp(before, "gi"), after);
}
console.log(myReplace("He is Sleeping on the couch.", "Sleeping","sitting"));
Aditya
@ezioda004
Jan 13 2018 16:56
@Skidragon Put const isFirstLetterUpperCase = str => str[0] === str[0].toUpperCase(); inside the function and it'll work.
alpox
@alpox
Jan 13 2018 16:57
@Skidragon It should work like this already. Try to clear the browser cache and reload
@ezioda004 Doesn't have to be. This is only a function definition
Simon Davis
@Skidragon
Jan 13 2018 16:59
Thanks guys :)
Aditya
@ezioda004
Jan 13 2018 17:05
@alpox Ow right, it does work but it gives syntax error.
Kelechi Chinaka
@ke1echi
Jan 13 2018 17:13
i think am going to do a dual boot (win & ubuntu) @forkerino
Brian
@BrianCodes33
Jan 13 2018 17:46
function findMissing(arr1, arr2) {
   return arr1.map((num) => {
    if (arr2.indexOf(num) === -1) {
      return num;
    }
  })
}
findMissing([1, 2, 3], [1, 3])
any help here?
think i found a diff solution
function findMissing(arr1, arr2) {
   return arr1.filter((a) => {
     return !arr2.includes(a)
   })
}
Simon Davis
@Skidragon
Jan 13 2018 17:51
@BrianCodes33 you could also use arr1.find instead of arr1.map
if you just want one missing number
Brian
@BrianCodes33
Jan 13 2018 17:52
function findMissing(arr1, arr2) {
   return arr1.find((a) => {
     return !arr2.includes(a)
   })
}
ok im getting 3 out of 5 tests passing
not passing for these
Test.assertEquals(findMissing([4, 3, 3, 61, 8, 8], [8, 61, 8, 3, 4]), 3);
Test.assertEquals(findMissing([0, 0, 0, 0, 0], [0, 0, 0, 0]), 0);
Simon Davis
@Skidragon
Jan 13 2018 17:54
whats the third argument?
Brian
@BrianCodes33
Jan 13 2018 17:55
?
Simon Davis
@Skidragon
Jan 13 2018 17:55
the 3 and 0 at the end
Brian
@BrianCodes33
Jan 13 2018 17:55
thats the return value
Simon Davis
@Skidragon
Jan 13 2018 17:55
oh xD
Brian
@BrianCodes33
Jan 13 2018 17:56
i see the problem. just not sure how to transfer it in code
Simon Davis
@Skidragon
Jan 13 2018 17:56
yeah me too
Brian
@BrianCodes33
Jan 13 2018 17:58
do you see the solution?
Simon Davis
@Skidragon
Jan 13 2018 17:59
All I can think of is just destroy every value and it would just leave the one remaining
Pieter Stokkink
@forkerino
Jan 13 2018 18:03
@BrianCodes33 you need to compare the number of occurrences of each element in both arrays. If one is more than the other, that is the value you need to return.
@kelechy that can work very well
but do make sure to back up important stuff.
Simon Davis
@Skidragon
Jan 13 2018 18:27
@BrianCodes33 Where is the findMissing problem? I want to test a solution.
Simon Davis
@Skidragon
Jan 13 2018 18:29
@BrianCodes33 Have you got it working yet?
Brian
@BrianCodes33
Jan 13 2018 18:30
im having trouble putting in test case for one value that may appear twice or more
Simon Davis
@Skidragon
Jan 13 2018 18:33
@BrianCodes33 I passed all the tests just want to figure out how Pieter Stokkink was saying how to solve the solution.
The way I solved it is with: filter, includes, splice, and indexOf.
Pieter Stokkink
@forkerino
Jan 13 2018 18:39
@Skidragon using .splice can work, although in real world situations I avoid it as the plague, as it changes an existing array and makes code unpredictable.
Pieter Stokkink
@forkerino
Jan 13 2018 18:45
another way to do it, still changing an existing array is to use .sort()
but I would prefer counting elements in both arrays and returning once you found the difference.
Ken Haduch
@khaduch
Jan 13 2018 18:47
@BrianCodes33 - I think that I would numerically sort the two arrays and then compare them until there wasn't a match and then return that value?
Pieter Stokkink
@forkerino
Jan 13 2018 19:00
I just did the kata and used a helper function called count to count the number of occurrences of an element in an array. Not sure if it is best practice performance wise, but it works.
Among the other solutions I see a gem. Hint: add things.
Simon Davis
@Skidragon
Jan 13 2018 19:08
@forkerino would going this route be alright? using objects to store the number of occurences of each number then comparing them. This is only a partial solution
function addNumOfOccurences(arr) {
  const obj = {};

  arr.forEach(number => obj[number] === undefined ? obj[number] = 1 : obj[number] += 1);
  return obj;
}

function findMissing(arr1, arr2) {

  let obj1 = addNumOfOccurences(arr1);
  let obj2 = addNumOfOccurences(arr2);
  console.log(obj1);
  console.log(obj2);
}
}
console.log(findMissing([4, 3, 5, 7], [4, 3, 7]));
Pieter Stokkink
@forkerino
Jan 13 2018 19:17
@Skidragon I guess it is fine, that was close to the first idea I had in mind. But then I didn't see the need to store the result in an object anymore and just compared it right away.
Kelechi Chinaka
@ke1echi
Jan 13 2018 19:26
i dont have any external drive to backup to @forkerino
Pieter Stokkink
@forkerino
Jan 13 2018 19:29
@kelechy well, I suggest you read if it is possible to create a dual boot without deleting any existing files (assuming you have enough free space). I think you will need a separate partition for it at least.
Kelechi Chinaka
@ke1echi
Jan 13 2018 19:31
alright
thanks @forkerino
CamperBot
@camperbot
Jan 13 2018 19:31
kelechy sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2968 | @forkerino |http://www.freecodecamp.org/forkerino
Can someone tell me why this throws that "$" is not defined
Pieter Stokkink
@forkerino
Jan 13 2018 19:51
@EricHasegawa I'm not getting that error...
Eric Hasegawa
@EricHasegawa
Jan 13 2018 19:51
Sorry I had my jQuery hooked up wrong
Pieter Stokkink
@forkerino
Jan 13 2018 19:52
@EricHasegawa btw the second argument to .on() should just be a function, not a string
Eric Hasegawa
@EricHasegawa
Jan 13 2018 19:52
I'm not sure why this doesn't work now, the console says it cannot create property 'guid' on string 'setTimeout(myFunction, 3000)'
Oh excellent that worked, thanks! @forkerino
CamperBot
@camperbot
Jan 13 2018 19:53
erichasegawa sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2969 | @forkerino |http://www.freecodecamp.org/forkerino
Eric Hasegawa
@EricHasegawa
Jan 13 2018 19:53
I was confused because I was following a vanilla JS tutorial while using jQuery
Pieter Stokkink
@forkerino
Jan 13 2018 19:55
:+1:
Eric Hasegawa
@EricHasegawa
Jan 13 2018 19:55
Is there any tutorials you would recommend for creating a basic timer in JS
I can't seem to find one that's solid
Pieter Stokkink
@forkerino
Jan 13 2018 19:57
@EricHasegawa I have no idea. I used setInterval() (it's like setTimeout, but repetitive)
Eric Hasegawa
@EricHasegawa
Jan 13 2018 19:57
Yeah I'll figure it out, thanks anyway!
Pieter Stokkink
@forkerino
Jan 13 2018 19:58
I remember reading a lot on MDN, but haven't seen a tutorial
There are youtube videos where they walk you through a solution for this specific project.
But I guess you would want to try something first.
Eric Hasegawa
@EricHasegawa
Jan 13 2018 20:02
Yeah I've followed a few of those for past projects, I can't seem to feel confident in my learning if I do that though
Pieter Stokkink
@forkerino
Jan 13 2018 20:05
@EricHasegawa definitely keep going at it on your own first (maybe with a little help here and there by asking pointed questions). There's a lot of value in finishing it yourself first, even if the result is not as good as you want it to be.
Eric Hasegawa
@EricHasegawa
Jan 13 2018 20:06
Yeah for sure
Uriel Guzmán
@Burinson
Jan 13 2018 20:30
if (five &&
    seven &&
    six === you &&
    one &&
    nine &&
    three === AI &&
    four &&
    eight === "")
How could I rewrite this code so that it groups the chained variables correctly?
To something like:
if ((five, seven, six === you) && (one, nine, three === AI) && (four, eight === ""))
Stephen James
@sjames1958gm
Jan 13 2018 20:50
@Burinson are you trying to compare five, seven and six each to you
That is five == you and six == you and seven == you ?
Uriel Guzmán
@Burinson
Jan 13 2018 20:56
@sjames1958gm Yes
Stephen James
@sjames1958gm
Jan 13 2018 20:57
Then your first if is wrong as well you have to compare each one separately.
if (five == you && seven == you && six == you ...)
Uriel Guzmán
@Burinson
Jan 13 2018 20:57
@sjames1958gm Thanks
CamperBot
@camperbot
Jan 13 2018 20:57
burinson sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8851 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
CamperBot
@camperbot
Jan 13 2018 21:56
github-henry sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8852 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Henry
@GitHub-Henry
Jan 13 2018 22:07
@sjames1958gm you need to treat yourself when you hit 10K.
I'd say thanks for being there to help out folks, but they
ban folks for that, so I can't, but I would if I could.
:shipit: :dizzy:
CamperBot
@camperbot
Jan 13 2018 22:07
github-henry sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
api offline
Stephen James
@sjames1958gm
Jan 13 2018 22:16
@GitHub-Henry :)
mstellaluna
@mstellaluna
Jan 13 2018 22:26
@GitHub-Henry yes because spamming the rooms with walls of text which bot generates on each one is against the code of conduct :)
Garrus Napp
@GarrusNapp
Jan 13 2018 22:40
you just don't have anything better to do