These are chat archives for FreeCodeCamp/HelpJavaScript

25th
Jun 2018
Aditya
@ezioda004
Jun 25 2018 00:06
@ArchivalBoat50
const array = [1, 1.5, 2, 2.5];
const integer = array.filter(num => num % 1 == 0 ? true : false);
console.log(integer);
ArchivalBoat50
@ArchivalBoat50
Jun 25 2018 00:14
@ezioda004 Ok thanks, but what if I wanted to do an operation like squaring the integer?
Aditya
@ezioda004
Jun 25 2018 00:22
@ArchivalBoat50 Squaring on this filtered array or previous array? You can chain these functions so like .filter().map() etc
ArchivalBoat50
@ArchivalBoat50
Jun 25 2018 00:23
@ezioda004 Squaring on that filtered array
I'm just trying to square the integers
Aditya
@ezioda004
Jun 25 2018 00:25
@ArchivalBoat50 Like this const squares = array.filter(num => num % 1 == 0 ? true : false).map(num => num ** 2);
ArchivalBoat50
@ArchivalBoat50
Jun 25 2018 00:28
@ezioda004 Oh yeah you use the map function to get a new array
@ezioda004 Thanks
Aditya
@ezioda004
Jun 25 2018 00:31
@ArchivalBoat50 No problem! Also another way with using only .reduce()
array.reduce((accum, curr) => curr % 1 == 0 ? accum.push(curr ** 2) && accum : accum, []);
Its kinda like both .map() and .filter() mixed together.
Jonathan
@skillt3ch
Jun 25 2018 06:28
hey all!
here’s my code:
function printManyTimes(str) {
  "use strict";

  // change code below this line

  const SENTENCE = str + " is cool!";
  for(let i = 0; i < str.length; i+=2) {
    console.log(SENTENCE);
  }

  // change code above this line

}
printManyTimes("freeCodeCamp”);
and the error i get:
// running test
Unexpected token ?
// tests completed
console.log should be changed to print the SENTENCE variable.
it looks like my code is already telling console.log to print the SENTENCE variable
anyone else getting this issue, or can tell me where i’ve gone wrong?
Markus Kiili
@Masd925
Jun 25 2018 06:56
@skillt3ch There is a problem with the ending double quote "freeCodeCamp” <- Try to write those quotes again.
Jonathan
@skillt3ch
Jun 25 2018 06:56
ohhh
cool
i’ll give that a shot
@Masd925 same issue
i checked the forums, there’s a bug unfortunately
Yes, it is a bug. The regex that verifies the console.log(SENTENCE); is broken :slight_smile:
Markus Kiili
@Masd925
Jun 25 2018 07:02
@skillt3ch ok. Just go to the next challenge.
Jonathan
@skillt3ch
Jun 25 2018 07:06
@Masd925 thank you
Ogundele Olumide
@Lumexralph
Jun 25 2018 08:02
@Masd925 good morning
Markus Kiili
@Masd925
Jun 25 2018 08:05
@Lumexralph Hi.
Blauelf
@Blauelf
Jun 25 2018 08:17
Good morning
Simon Cordova
@gbsimon87
Jun 25 2018 08:47
Morning everyone
Blauelf
@Blauelf
Jun 25 2018 09:03
I always find it funny that Greenwich is GMT+1 most of the year :D
Markus Kiili
@Masd925
Jun 25 2018 09:04
@Blauelf You are a programmer. x = x + 1. No problem.
Blauelf
@Blauelf
Jun 25 2018 09:05
Yeah, but that's somewhat recursive. GMT = Greenwich Mean Time.
Markus Kiili
@Masd925
Jun 25 2018 09:05
But yeah, that is quite funny.
@Blauelf In my friends job, there is a bonus if you get enough points that they somehow measure. People get pissed if they get one point below that line, so they made that you get the bonus also if you end with one point below the line.
Blauelf
@Blauelf
Jun 25 2018 09:10
Which makes them pissed if they get two points below that line.
Markus Kiili
@Masd925
Jun 25 2018 09:11
No, they apparently don't.
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 09:56
Guys can I use .apply() to flatten an array?
Blauelf
@Blauelf
Jun 25 2018 09:59
You can.
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 09:59
Noooo, you spoiled it!
Waaaa!!
I still remember the solution.
Anyway, what does .apply() do anyway?
I struggle to understand it from MDN.
Markus Kiili
@Masd925
Jun 25 2018 10:01
@OGTechnoBoy Put (r) after the question, if it is a rhetorical one.
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 10:01
Oh, I didn't know that, I'm new to this place.
Blauelf
@Blauelf
Jun 25 2018 10:05

@OGTechnoBoy If you say someObject.someMethod(arg1, arg2, arg3) that's about equivalent to someObject.someMethod.call(someObject, arg1, arg2, arg3) or someObject.someMethod.apply(someObject, [arg1, arg2, arg3]). So if you had a number of arguments in an array or even array-like and wanted to pass it to a function, prior to ES6 spread operator you would have used apply.

Like

var nums = [2, 32, 42, 8, 16, 4];
var max = Math.max.apply(null, nums); // Math.max does not care about "this", so can be null

With ES6 we can

var max = Math.max(...nums);
Remember: "apply" with "array". Those look similar.
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 10:08
So...the replacement of apply is spread operator, right?
Then why this doesn't work?

function steamrollArray(arr) {
// I'm a steamroller, baby
return [].concat(...arr);
}

steamrollArray([1, [2], [3, [[4]]]]);

Isn't spread operator supposed to get out the values from the arrays?
It works on 2 and 3 but not on 4, why that?
Markus Kiili
@Masd925
Jun 25 2018 10:22
@OGTechnoBoy Using concat like that removes one level of nesting. The level of nesting is not known, so you need to use recursion or a loop of some kind.
What you get from your code is [ 1, 2, 3, [ [ 4 ] ] ].
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 10:24
Yeah but the question is how I should stop the loop/recursion
If I started a recursion, it will surely remove all levels of nesting, yes but how I stop it when it done?
There are no a way to know the level of nesting, no?
Markus Kiili
@Masd925
Jun 25 2018 10:24
@OGTechnoBoy You can check if an element is an array or not.
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 10:24
Yeah but how that is useful to me?
Markus Kiili
@Masd925
Jun 25 2018 10:25
If all the array elements are not arrays, the result is done.
You can for example concat like that until all the array elements are not arrays.
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 10:26
Oh yeah!
That's an amazing way. Thank you!!
Markus Kiili
@Masd925
Jun 25 2018 10:27
@OGTechnoBoy With recursion, you can start by checking if the arguments is an array or not, and then use a loop over elements and a recursive call that uses steamrollArray to flatten the array elements.
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 10:29
I did that(except loop) but it didn't work
it seems that there are a lot of "recursion"
Markus Kiili
@Masd925
Jun 25 2018 10:31
@OGTechnoBoy There are many ways to solve it with recursion. Recursion just means that a function calls itself inside the function code.
Simplest way for it is to use steamrollArray to flatten the array elements. Using an inner function is one way but somewhat more complex.
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 10:35

function steamrollArray(arr) {
// I'm a steamroller, baby
if (Array.isArray(...arr) === false) {return [...arr];}
return steamrollArray([].concat(...arr));
}

steamrollArray([1, [2], [3, [[4]]]]);

It doesn't work.
It only passes the first test(Yaaay!) but the other tests doesn't work
It seems that the problem is that when at least 1 item is non-array, it stops everything and nothing works.
But if all arrays were nested then it works properly, I guess.
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 10:40
How I could check if 1 item is at least an array.
Nate Mallison
@NJM8
Jun 25 2018 10:44
add another loop to scan ahead in the current row?
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 10:47
Why?
Nate Mallison
@NJM8
Jun 25 2018 10:49
to check for an array yeah?
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 10:50
But I'm not sure how a loop would help.
When the recursion runs then the function would reset as well.
So the loop would reset as well.
I don't understand.
Jonathan
@skillt3ch
Jun 25 2018 10:54
how about you create a new array and create a function that pushes an element to it if it is not an array
and if it is an array, then it loops through it and uses recursion on that array
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 10:56
It seems that the function I made works
But at the fourth running, it fails.
Look at this:
Array(4) [ 1, 2, 3, (1) […] ]
debugger eval code:4:3
Array(4) [ 1, 2, 3, (1) […] ]
debugger eval code:4:3
Array(4) [ 1, 2, 3, 4 ]
debugger eval code:4:3
Array(4) [ 1, 2, 3, (1) […] ]
@skillt3ch Good idea.
Jonathan
@skillt3ch
Jun 25 2018 10:58
@OGTechnoBoy :thumbsup:
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 11:01
I have no idea why it doesn't work.
Simon Cordova
@gbsimon87
Jun 25 2018 11:06
For the 'Basic Algorithm Scripting: Return Largest Numbers in Arrays' challenge.
I've create this code, and it works, but not sure if it's recommended to use Infinity in such a case.
I had tried with 0, but then the negative numbers are obviously smaller, so I used -Infinity to account for this.
Any other suggestions?
function largestOfFour(arr) {
  var results = [];
  for (var n in arr) {
      var largestNumber = -Infinity;
      for (var sb in arr[n]) {
          if (arr[n][sb] > largestNumber) {
              largestNumber = arr[n][sb];
          }
      }
    results[n] = largestNumber;
}
  return results;
}

largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]])
Markus Kiili
@Masd925
Jun 25 2018 11:06
@gbsimon87 Using -Infinity here is fine.
Another way is to start with the first subarray element.
Simon Cordova
@gbsimon87
Jun 25 2018 11:07
@Masd925 thanks, but would there be any 'floating point' bugs to account for?
Markus Kiili
@Masd925
Jun 25 2018 11:07
@gbsimon87 No, I can't imagine any problems from that.
Simon Cordova
@gbsimon87
Jun 25 2018 11:08
Fair enough, cheers man
Markus Kiili
@Masd925
Jun 25 2018 11:10
@gbsimon87 In general, using the for...in loop to loop over array indices is not a good idea, because the order of iteration is not guaranteed to be the insertion order. A simple for loop or an array iterator is better.
Simon Cordova
@gbsimon87
Jun 25 2018 11:12
Thanks, I actually remember that from before now that you mentioned it
Would this also be the case with maps and sets?
I hear they've got some additional features
Tbh I could probably just research this instead of taking your time :smile:
Markus Kiili
@Masd925
Jun 25 2018 11:15
@gbsimon87 They are iterated in insertion order.
Simon Cordova
@gbsimon87
Jun 25 2018 11:29
oh nice, that's good to know, thanks a lot
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 11:33
Yaay it worked!
It seems that the problem was forEach loop
I changed it to for...in and it worked.
Blauelf
@Blauelf
Jun 25 2018 12:01
@gbsimon87 If you use Math.max like ES5 results[n] = Math.max.apply(null, arr[n]); or ES6 results[n] = Math.max(...arr[n]);, it results in -Infinity for empty arrays, so you're in good company with that one.
@OGTechnoBoy I used arr.some(Array.isArray) to check whether any of the elements of arr is an array itself.
Blauelf
@Blauelf
Jun 25 2018 12:09
I also used a while loop instead of tail recursion. I don't trust tail recursion optimisation to eliminate the costs. We are not in Haskell.
Simon Cordova
@gbsimon87
Jun 25 2018 12:12
@Blauelf thanks for the further insight
Blauelf
@Blauelf
Jun 25 2018 12:17
@gbsimon87 I don't think one should use for..in on maps. I would use methods like keys or entries and iterate those with a for..of loop instead. Or use forEach method. But for..in is often a bit fragile.
for..in for example considers all enumerable properties, also those "inherited" (via prototype chain). So there's much code like
for (key in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, key)) {
        // key is not inherited
    }
}
Object.prototype instead of obj in case prototype chain is broken (I used to create objects with Object.create(null))
Simon Cordova
@gbsimon87
Jun 25 2018 13:05
Thanks @Blauelf , I'll definitely need to research that more, I've embarked on a new mission to gain a very deep level understanding of data structures
starting with arrays and objects
Jason Luboff
@JLuboff
Jun 25 2018 15:18
@revisualize I am now
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 15:49
Guys why here it says letter.push is not a function

function pairElement(str) {
var letters = {
A: "T",
T: "A",
C: "G",
G: "C",
}
var array = [];
for(var i = 0; i < str.length; i++) {
array.push([str.charAt(i)]);
for (var letter of array[i]) {
letter.push(letters[str.charAt(i)]);
console.log(letter);
}
}
return array;
}

pairElement("GCG");

I checked its type. It seems that it is "string"
Jason Luboff
@JLuboff
Jun 25 2018 15:51
@OGTechnoBoy Becuase letter does not exist
or sorry
letter is not an array
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 15:51
Yeah it is "string"
Jason Luboff
@JLuboff
Jun 25 2018 15:51
it's an iterator
.push() is an array method
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 15:51
How I'm supposed to iterate it then?
By using for...in or for loop?
Jason Luboff
@JLuboff
Jun 25 2018 15:52
well what are you trying to do? You can only use .push() on an array
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 15:52
I'm trying to push an item to the sub-array in the array
How I'm supposed to do that?
By using for loop?
Jason Luboff
@JLuboff
Jun 25 2018 15:54
In the array array? If that is that cause..you need to do something like array.push([value1, value2]) if you want to push in a sub-array
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 15:55
Wait, there are something like that?
Wow, I'm using push since I'm starting and never used the second property
Hahaa, awesome.
Jason Luboff
@JLuboff
Jun 25 2018 15:56
I'm not using a second property, I'm just pushing an array into an array
Blauelf
@Blauelf
Jun 25 2018 15:57
Why does this sound like a "Yo Dawg" meme?
Jason Luboff
@JLuboff
Jun 25 2018 15:58
Yo dawg, I'mma push an array into your array
Jason Luboff
@JLuboff
Jun 25 2018 15:59
:joy:
Blauelf
@Blauelf
Jun 25 2018 15:59
Other people did it before.
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 16:00
Nevermind. I just solved it minutes ago.
The infinite loop freaking ruined everything.
Which reminds me, what infinite loops/stack overflows are useful for?
Jason Luboff
@JLuboff
Jun 25 2018 16:01
Infinite loops are never useful
an infinite loop literally breaks things
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 16:02
They seem pretty useful to me as all what they do is just harming CPU.
Blauelf
@Blauelf
Jun 25 2018 16:04
Infinite loops are useful. Just usually on a bigger scale. Like the weather station checking temperature sensors and displaying values in an infinite loop.
Blauelf
@Blauelf
Jun 25 2018 16:06
@tejaykodali If you mean the last check, to me it seems to be broken.
Jason Luboff
@JLuboff
Jun 25 2018 16:06
I agree. Last check is broken
Teja Kodali
@tejaykodali
Jun 25 2018 16:06
Alright, thanks
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 16:07
However, I heard that video games use infinite loops, but how they do that while keeping staple to CPU?
Blauelf
@Blauelf
Jun 25 2018 16:10
They do all the work in the infinite loop, and also there are interrupts, code executed on an event, interrupting any other code currently running. Can be events like "timer that fires every 55ms" or "byte available on serial interface" or "user smashing on keyboard" or a few software-defined ones.
With the s flag we no longer need [\s\S] for matching any character, even line break.
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 16:15
Some stuff you really wish were supported in your browser
Like flat function
Blauelf
@Blauelf
Jun 25 2018 16:15
Who needs a "flat" function when you can easily build your own with more control over the process?
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 16:15
I mean wow, if something like that existed, I wouldn't waste 2 days trying to flatten an array.
I mean hey! why you need push when you could easily build your own with more control? .../s
Blauelf
@Blauelf
Jun 25 2018 16:17
Push/pop are used pretty frequently on stacks. They are some of the most basic methods.
Implementing them in the browser allows for optimized implementations, much faster than pure JavaScript ones.
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 16:18
flat function is needed too, you know.
Blauelf
@Blauelf
Jun 25 2018 16:18
But why? Who needs it if they don't at the same time are able to use concat?
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 16:20
I will be honest, to flatten an array is pretty hard and takes a lot of time.
Blauelf
@Blauelf
Jun 25 2018 16:20
With ES6, flattening by one level is just [].concat(...arr). Works for arrays up to a few ten thousand elements (depending on browser).
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 16:20
If my solution is the best, then it takes if statements and recursions to do it.
So I rather have a ready function for that. I don't know how that would hurt it.
Blauelf
@Blauelf
Jun 25 2018 16:22
I used like while (arr.some(Array.isArray)) arr = [].concat(...arr); return arr;, but that would be evil if called with like var arr = []; arr[0] = arr; steamrollArray(arr);. The recursive solution would at least crash due to stack overflow.
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 16:23
Oh, I used recursion.
I don't know about you but most of time I forget all loops besides for loop. Is that bad?
Blauelf
@Blauelf
Jun 25 2018 16:30
There are only five kinds of loops, while, do..while, for, for..in, for..of. Unless there's something new I don't know about. Replacing a loop with recursion is fine in Haskell (its loops actually use tail recursion, which is implemented in an efficient way), but not exactly in JavaScript. Safari seems the only browser to support it (which is surprising, as Safari usually is the worst browser to develop for if you ignore long-abandoned IE)
jusgoose
@gusd773
Jun 25 2018 17:09
anybody on here use Atom? I installed the platformio ide terminal, while it does allow me to open up a new terminal it does not allow me to type anything in it nor does any green text pop up showing the directory of the current file
as such
image.png
Brad
@bradtaniguchi
Jun 25 2018 17:09
@gusd773 Are you on windows?
Yup you are
jusgoose
@gusd773
Jun 25 2018 17:09
@bradtaniguchi yessir I have previously been able to use the terminal tho
Brad
@bradtaniguchi
Jun 25 2018 17:09
You could try to debug the problem like a web-page, otherwise check for updates/restart atom itself
jusgoose
@gusd773
Jun 25 2018 17:09
idk why now it hates me
twas an update needed forgive me
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 17:11
Btw, what is tail recursion?
Jason Luboff
@JLuboff
Jun 25 2018 17:11
I use Atom...but use my Node JS seperate CLI....so I guess I'm really not adding anything to this convo
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 17:11
And is it supported in Javascript?
jusgoose
@gusd773
Jun 25 2018 17:11
I wish somebody would've told me computers were so coldhearted
Brad
@bradtaniguchi
Jun 25 2018 17:12
@OGTechnoBoy Heres a SO post that shows a great example:
jusgoose
@gusd773
Jun 25 2018 17:12
SUCCESS
@bradtaniguchi thank you
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 17:12
@bradtaniguchi Thank you but is it supported in Javascript?
Brad
@bradtaniguchi
Jun 25 2018 17:13
It is, BUT to my knowledge it isn't that efficient compared to some languages.
Nate Mallison
@NJM8
Jun 25 2018 17:14
Hey all, can I get a little feedback on this app? https://natethedev-vuetodo.herokuapp.com It's for a job interview. Fingers crossed
Jason Luboff
@JLuboff
Jun 25 2018 17:15
@NJM8 It's unclear that I'm supposed to press enter to create the new list, I thought I had to click Add List again which in turn wasn't doing anything
Looks like thats the same behavior on the Add To Do
Nate Mallison
@NJM8
Jun 25 2018 17:16
placeholder="enter to submit" ?
Jason Luboff
@JLuboff
Jun 25 2018 17:17
That would be a bit more clear, yes
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 17:17
@bradtaniguchi Yeah, I read about it and it seems that it's very slow compared to other languages.
Nate Mallison
@NJM8
Jun 25 2018 17:19
@JLuboff Thanks
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 17:40
Guys how I could know that what is the key and what is the property?
Like there are Name: "Hello"
How I could check that Name is they key and "Hello" is the value?
Markus Kiili
@Masd925
Jun 25 2018 17:45
var obj = {Name: "Hello"};

Object.keys(obj); // [ 'Name' ]
obj.hasOwnProperty("Name"); // true
"Name" in obj; // true
obj["Name"]; // "Hello" 
Object.values(obj).includes("Hello"); // true
@OGTechnoBoy Hope that that helps.
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 17:46
Ah, then that's how it works.
Thank you!
Markus Kiili
@Masd925
Jun 25 2018 17:46
@OGTechnoBoy Note that values and includes are ES6 methods, so they don't work on older browsers.
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 17:54
@Masd925 I really don't care for that. I'm only using it for challenges
Jason Luboff
@JLuboff
Jun 25 2018 17:55
If you're learning to use the knowledge gained for job placement, you will very much care...
OGTechnoBoy
@OGTechnoBoy
Jun 25 2018 17:55
I'm not planning for a job placement
I'm just doing it for fun.
So these stuff really don't matter for me.
Markus Kiili
@Masd925
Jun 25 2018 17:57
@JLuboff Yo.
Jason Luboff
@JLuboff
Jun 25 2018 17:58
What up
Markus Kiili
@Masd925
Jun 25 2018 18:31
@JLuboff Java.
Jason Luboff
@JLuboff
Jun 25 2018 18:32
Fun..
Markus Kiili
@Masd925
Jun 25 2018 18:32
I will not sleep until I have read through my old java examples from school.
Jason Luboff
@JLuboff
Jun 25 2018 18:32
That does not sound like fun
Brad
@bradtaniguchi
Jun 25 2018 18:35
reading, java, old examples, school. None of those things sound fun
Markus Kiili
@Masd925
Jun 25 2018 18:39
How about coffee and chocolate. Jing and jang.
Jason Luboff
@JLuboff
Jun 25 2018 18:40
I like chocolate. Dark. Single Origin. Mmmm
Markus Kiili
@Masd925
Jun 25 2018 18:42
I are the chocolate and drunk the coffee but the code and notes are still there.
anthonygallina1
@anthonygallina1
Jun 25 2018 18:49
:smile:
I have this Java Cookbook: Solutions and Examples for Java Developers But havent found where I put it yet. Boy am I going to be happy when I find it. Hard cover. Will be like finding a present.
Brad
@bradtaniguchi
Jun 25 2018 18:57
I have a stack of books I should read, hadly have picked them up lately, just no time to read haha
Brad
@bradtaniguchi
Jun 25 2018 19:24
The last book I read was the phoenix project, pretty interesting read
jusgoose
@gusd773
Jun 25 2018 20:02
can anybody help? I am having trouble with "php artisan migrate" it gives me this error
image.png
Jason Luboff
@JLuboff
Jun 25 2018 20:17
@gusd773 According to the rror... the type of collation you're using is not valid...
Hell...a quick google search for "utf8mb4_unicode_ci" came up with this.. https://stackoverflow.com/questions/29916610/1273-unknown-collation-utf8mb4-unicode-ci-cpanel
Bjorn van de Peut
@bjorno43
Jun 25 2018 20:30
@JLuboff The code in that answer uses mysql_* functions. Those are deprecated in PHP these days. They won't work in PHP7+
Daniel Simeonov
@dbsimeonov
Jun 25 2018 21:04
Guys I think I made a mistake,
Currently I'm creating my hardcoded json file that contains all my data, and realized after finishing it that some of my elements are stored in Object instead of Array. So my question is, can I loop thru with javascript each item from the Object ?
Markus Kiili
@Masd925
Jun 25 2018 21:07
@dbsimeonov You can. One way is to for loop over an array Object.keys(obj) that holds the keys and then access the values with bracket notation.
for...in loop can also be used.
Daniel Simeonov
@dbsimeonov
Jun 25 2018 21:12
@Masd925 Actually I was just reading about for..in loop. So its exactly the same as .forEach isn't it? As I've neever used it before
Markus Kiili
@Masd925
Jun 25 2018 21:13
@dbsimeonov for...in loops over enumerable property keys of the object and the prototype chain. foreach is an array method for running a function once for each array element.
For plain objects, for...in loop and looping over Object.keys(obj) do the same.
Daniel Simeonov
@dbsimeonov
Jun 25 2018 21:20
So basically doesn't matter if its array or object?
from the functional side?
actually nvm, I will re-write it to be safe and feel more comfortable
Markus Kiili
@Masd925
Jun 25 2018 21:22
@dbsimeonov If the order matters, you need to use an array.
Daniel Simeonov
@dbsimeonov
Jun 25 2018 21:27
and one more question as I couldn't remember or find it in the mdn, accessing elements from array can be done only with dot notation (i think that was the name) arr[1] ? If i'm looking for specific name?
Markus Kiili
@Masd925
Jun 25 2018 21:29
@dbsimeonov You can use dot notation if you know the key string (and write it after the dot). In all other cases, you need to use the more general bracket notation. For example you need to use bracket notation if the key needs to be evaluated from a variable or an expression.
Markus Kiili
@Masd925
Jun 25 2018 21:39
With dot notation the key also needs to be a valid JS identifier name. That is why arr.1 doesn't work with arrays.
Jason Luboff
@JLuboff
Jun 25 2018 22:57
@bjorno43 Eh. This is a Javascript chat room, not PHP so I still provided something :smile:
Markus Kiili
@Masd925
Jun 25 2018 23:00
@JLuboff Thanks.
Jason Luboff
@JLuboff
Jun 25 2018 23:02
@Masd925 ;)