These are chat archives for FreeCodeCamp/Help

17th
Sep 2018
Kyle Holm
@thekholm80
Sep 17 2018 00:02
it really helped me to learn what things are called - not because knowing the names of things makes them easier to understand, but because then i knew what to google when it all went pear shaped
Karma Drukpa
@coderkarma
Sep 17 2018 00:11
@thekholm80 ok sir.
Kyle Holm
@thekholm80
Sep 17 2018 00:12
unless you're a Patrick Rothfuss fan, then knowing the names of things gives you power over them
Karma Drukpa
@coderkarma
Sep 17 2018 00:13
idk who is patrick , i have to google it now.
Kyle Holm
@thekholm80
Sep 17 2018 00:13
he's an author
fiction
Karma Drukpa
@coderkarma
Sep 17 2018 00:14
I see. I have been trying to implement this arrow functions and higher order functions
Karma Drukpa
@coderkarma
Sep 17 2018 01:47
I need a help @bjorno43 @thekholm80 @Manish-Giri
Kyle Holm
@thekholm80
Sep 17 2018 01:51
@coderkarma which part are you stuck on?
Karma Drukpa
@coderkarma
Sep 17 2018 01:58
@thekholm80 let me sent you my attempted code.
function getIndexToIns(arr, num) {
    // Find my place in this sorted array.
    arr.sort((a,b) => {return a -b})
    let index = 0;
    // if last ele of sorted arr is less then given num then return the length of arr
    if(arr[arr.length -1] < num ){
        return arr.length;
    }

    for (let i = 0; i <arr.length; i++){
        let ele = arr[i];
        let next = arr[i + 1];
        // if current ele is equals to num it should return idex of that element
        if(ele === num){
           return i;
           // if current value  is greater then num given  and num is less then next 
        } else if(ele > num && num < next){
           return  i + 1;
           // if current value is less then num with floating point
        } else if(ele < parseFloat(num)){
                return next;
            } 
        }
    return i ;
}
console.log(getIndexToIns([5, 3, 20, 3], 5)) //should return 2.
             // 3  3  5   20
my approach seems wrong may be @thekholm80
Kyle Holm
@thekholm80
Sep 17 2018 02:32
@coderkarma so you're sorting small to large, how does this work?
// if current value  is greater then num given  and num is less then next 
        } else if(ele > num && num < next){
Bjorn van de Peut
@bjorno43
Sep 17 2018 02:33
My best solution so far is
function getIndexToIns(arr, num) {
  let result = arr.sort((a, b) => a - b).findIndex(e => num <= e);
  result = result === -1 ? arr.length : result;
  return result;
}
Karma Drukpa
@coderkarma
Sep 17 2018 02:38
@kyle damn.. i never realize that sorry.
Kyle Holm
@thekholm80
Sep 17 2018 02:39
well i guess it does work, but for something like num = 3, ele = 4, next = 5 that will eval true
and i'm not sure that's what you want
by 'work' i mean it's a valid statement, but probably not what you want
Tom
@moT01
Sep 17 2018 02:51
anyone done the helmet lessons by chance?
Bjorn van de Peut
@bjorno43
Sep 17 2018 02:55

@thekholm80 I need your help improving this:

function getIndexToIns(arr, num) {
  return arr.sort((a, b) => a - b).findIndex(e => num <= e) === -1 ? arr.length : arr.sort((a, b) => a - b).findIndex(e => num <= e);
}

It works. But it's ugly. The ternary forces me to have a false condition. There should be a way to only have a true condition. Like return the sort unless it's -1?

Normally I'd just do return arr.sort((a, b) => a - b).findIndex(e => num <= e) || arr.length. But that only works if sort would return false instead of -1
Kyle Holm
@thekholm80
Sep 17 2018 03:01
that's pretty ugly from a performance pov
but that's the way golf goes
you could use reduce instead of findIndex
i think
const getIndexToIns = (arr, num) => arr.sort((a, b) => a - b).reduce((a, b, i, copy) => !a && b < copy[i + 1] ? i : a, false);
something like that i think, haven't tested it
Kyle Holm
@thekholm80
Sep 17 2018 03:11
wait, i think the reduce accumulator should be initialized with arr.length and the ternary eval be something like i < a && b < copy[i + 1]
i guess i could actually load the challenge and try it
Kyle Holm
@thekholm80
Sep 17 2018 03:21
lol i was way wrong
Bjorn van de Peut
@bjorno43
Sep 17 2018 03:21
Ye I thought so. I can't get it fixed, lol
Kyle Holm
@thekholm80
Sep 17 2018 03:23
my eval is wrong i wasn't using num anywhere lol
Bjorn van de Peut
@bjorno43
Sep 17 2018 03:53
Meh. The problem I'm having with reduce is that it keeps going after the condition evaluates true. So it returns the wrong index
Like:
false: 0
false: 1
false: 2
true: 3
true: 4
returns 4 instead of 3
Aditya
@ezioda004
Sep 17 2018 03:56
function getIndexToIns(arr, num) {
  return +(arr.sort((a, b) => a-b).reduce((a, c, i) => a = (a || (c >= num ? ""+i:a)), null) || arr.length);
}
A bit hacky
Kyle Holm
@thekholm80
Sep 17 2018 04:00
why coerce it to a string?
i feel like i'm missing something
Aditya
@ezioda004
Sep 17 2018 04:02
Cause if index is 0, 0 || arr.length would return arr.length
Kyle Holm
@thekholm80
Sep 17 2018 04:02
oh right
because 0 is false
Aditya
@ezioda004
Sep 17 2018 04:03
Still not a great solution, because it loops till the last element
If only there was a way to stop .reduce
Kyle Holm
@thekholm80
Sep 17 2018 04:04
they should make a stopEverythingAndReturnThisValueFromThisMethod(value)
Aditya
@ezioda004
Sep 17 2018 04:06
Time to write a proposal to TC39
Kyle Holm
@thekholm80
Sep 17 2018 04:06
like, reduce callback args could be (accumulator, reducer, index, copyOfArray, haltAndReturn)
Aditya
@ezioda004
Sep 17 2018 04:06
I think its doable
Kyle Holm
@thekholm80
Sep 17 2018 04:09
but i guess that would be the same as arr[arr.findIndex(callback)]
i'm pretty sure it halts at the first match
Aditya
@ezioda004
Sep 17 2018 04:10

Thats the purpose right?

function getIndexToIns(arr, num) {
  let result = arr.sort((a, b) => a - b).findIndex(e => num <= e);
  result = result === -1 ? arr.length : result;
  return result;
}

This solution is better than reduce

But is less cooler
Therefore ew
Kyle Holm
@thekholm80
Sep 17 2018 04:10
yeah findIndex() is the smart play but it makes for a really ugly one-liner
Bjorn van de Peut
@bjorno43
Sep 17 2018 04:16
Almost got it. Only issue is returning 0:
const getIndexToIns = (arr, num) => arr.sort((a, b) => a - b).reduce((a, c, i, copy) => { if(num <= c){ copy.splice(1); return i; } else { return copy.length } }, '');
Aditya
@ezioda004
Sep 17 2018 04:24
@thekholm80
Array.prototype.myReduce = function(cb, initial){
  let i = initial? 0 : 1;
  initial = initial || this[0];
  let prev = initial;
  for (;i < this.length; i++){
    let cur = cb(initial, this[i], i, this);
    if (cur == "stop") return prev;
    else {
      initial = cur;
      prev = initial;
    }
  }
  return initial;
}
Kyle Holm
@thekholm80
Sep 17 2018 04:27
you're missing an argument
reduce() has 3 args (2 optional)
reduce(callback, initial, this)
Aditya
@ezioda004
Sep 17 2018 04:28
a, c, i, arr
4 no?
Oh
Kyle Holm
@thekholm80
Sep 17 2018 04:28
4 for the callback
Aditya
@ezioda004
Sep 17 2018 04:28
I dont think it takes this ie 3rd argument
Kyle Holm
@thekholm80
Sep 17 2018 04:29
oh weird
Bjorn van de Peut
@bjorno43
Sep 17 2018 04:29
You can kill reduce by using arr.splice(1) on evaluating a true condition
Aditya
@ezioda004
Sep 17 2018 04:29
[1, 2, 3, 4, 5, 6].myReduce((a, c, i) => i == 2? "stop": a+c); //3
Bjorn van de Peut
@bjorno43
Sep 17 2018 04:29
Well technically you're not killing it. You're just removing the remaining elements
Kyle Holm
@thekholm80
Sep 17 2018 04:29
well what the crap am i thinking of?
Aditya
@ezioda004
Sep 17 2018 04:30
Mutating the original array is a no-no in my book
Kyle Holm
@thekholm80
Sep 17 2018 04:30
oh, map()
Aditya
@ezioda004
Sep 17 2018 04:31
Yeah, map, .filter and others have this
Kyle Holm
@thekholm80
Sep 17 2018 04:31
JS is dumb
i'm gonna learn PHP. at least it knows it's dumb
Aditya
@ezioda004
Sep 17 2018 04:33
The original dumb and dumber
psyperl
@psyperl
Sep 17 2018 04:34
<?php
echo '<script>document.write("hello world");</script>';
?>
Bjorn van de Peut
@bjorno43
Sep 17 2018 04:36
<textarea name='php'></textarea>

<?php

eval($_POST['php']);

?>
^ I'm sure nothing can go wrong
Supra01
@Supra01
Sep 17 2018 05:07
Hello I'm working on the Convert HTML Entries Algorithm and I'm not sure what I'm doing wrong.
function convertHTML(str) {
    let array =  [...str];
    let result = [];
   array.forEach(letter=>{
        if(letter === '&'){
            result.push("&amp;")
        };
        if(letter === '<'){
            result.push("&​lt")
            return;
        };
        if(letter === '>'){
            result.push("&​gt;")
            return;
        };
        if(letter === '"'){
            result.push("&​quot;")
            return;
        };
        if(letter === "'"){
            result.push("&​apos;")
            return;
        }
        result.push(letter)
    })
    return result.join('');
  }

console.log(convertHTML("Sixty > twelve"));
Claudio Restifo
@Marmiz
Sep 17 2018 05:11
@bjorno43 how you like PHP?
asking because @ work I'm gonna switch project occasionally and that means using php.
Is it really that bad? :smile:
I mean, can't honestly be worse that Node.js
Bjorn van de Peut
@bjorno43
Sep 17 2018 05:13
@Marmiz Honestly, it's more of hipe train than that it's actually that bad. Before PHP 7, it was bad. Node was definitely better. But since 7.0, it became a matter of preference between Node and PHP
Claudio Restifo
@Marmiz
Sep 17 2018 05:14
@Supra01 which test is failing? :)
Supra01
@Supra01
Sep 17 2018 05:14
Yup
Claudio Restifo
@Marmiz
Sep 17 2018 05:14
which one...
all of them?
Bjorn van de Peut
@bjorno43
Sep 17 2018 05:15
Ye all of those will fail cuz forEach is a callback function. It doesn't have access to result
Supra01
@Supra01
Sep 17 2018 05:15
image.png
@bjorno43 But when I run node it works. ....
image.png
@Marmiz Only the last test passes
Bjorn van de Peut
@bjorno43
Sep 17 2018 05:19
@Supra01 I guess JS being weird again. Anyway, why don't you simply do return encodeURI(str);?
@bobsbotty
encodeURI("This < should be > encoded");
bobsbotty
@bobsbotty
Sep 17 2018 05:22
@bjorno43 The result of your Javascript code is:
This%20%3C%20should%20be%20%3E%20encoded
Claudio Restifo
@Marmiz
Sep 17 2018 05:22

@Supra01 look at the

result.push("&​lt")

something's missing

same for the first if :)
Bjorn van de Peut
@bjorno43
Sep 17 2018 05:23
@bobsbotty
encodeURIComponent("This < should be > encoded");
bobsbotty
@bobsbotty
Sep 17 2018 05:23
@bjorno43 The result of your Javascript code is:
This%20%3C%20should%20be%20%3E%20encoded
psyperl
@psyperl
Sep 17 2018 05:28
@bobsbotty
btoa('check')
bobsbotty
@bobsbotty
Sep 17 2018 05:28
@psyperl There was an error with your Javascript code:
V8Js::compileString():2: ReferenceError: btoa is not defined
Aditya
@ezioda004
Sep 17 2018 05:28
@Supra01 You're pushing letter even if the character matches so theres extra letters, you can use else statement for last result.push(letter), also if you do that, you'll also have to change all if's except first one to else if otherwise it'll only account last if with else
switch statement is a lot better in this case
psyperl
@psyperl
Sep 17 2018 05:32
i've never seen nested switch before.. is that even possible?
Bjorn van de Peut
@bjorno43
Sep 17 2018 05:32
@bobsbotty
'Some < test " string >'.replace(/[\x26\x0A\<>'"]/g,function(r){return"&#"+r.charCodeAt(0)+";"});
bobsbotty
@bobsbotty
Sep 17 2018 05:32
@bjorno43 The result of your Javascript code is:
Some &#60; test &#34; string &#62;
psyperl
@psyperl
Sep 17 2018 05:32
i guess it's possible, maybe not practical
Supra01
@Supra01
Sep 17 2018 05:33
@Marmiz Thank you I added the colons and the return in the first IF statement
Bjorn van de Peut
@bjorno43
Sep 17 2018 05:36
@bobsbotty
'Some < test " string \''.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
bobsbotty
@bobsbotty
Sep 17 2018 05:36
@bjorno43 The result of your Javascript code is:
Some &lt; test &quot; string &apos;
Supra01
@Supra01
Sep 17 2018 05:36
@ezioda004 Thank you I agree there are better methods to do this. I will give the else statement a try.
I still don't understand why I was getting the correct results in node and the browser.
image.png
Claudio Restifo
@Marmiz
Sep 17 2018 05:48
@bjorno43 thanks for the insight :+1:
@Supra01 have you copied the strings from the challenge description?
if so don't do that. They have an extra char inside that you don't see them
Supra01
@Supra01
Sep 17 2018 05:51
image.png
Claudio Restifo
@Marmiz
Sep 17 2018 05:51
so your tests fails because it's not really &lt; but &(some unicode)lt;
Supra01
@Supra01
Sep 17 2018 05:51
After making the corrections @Marmiz suggested I ran each test case with node
@Marmiz ok I will give that a shot
Claudio Restifo
@Marmiz
Sep 17 2018 05:52
@Supra01 just go into your challenge and manually write each string
should pass
and learn: never copy paste strings from the web :)
Claudio Restifo
@Marmiz
Sep 17 2018 06:04
@Supra01 updates?
Supra01
@Supra01
Sep 17 2018 06:05
image.png
@Marmiz THANKS!!!!!
Claudio Restifo
@Marmiz
Sep 17 2018 06:05

:+1:

unicodes matters :sparkles:

Supra01
@Supra01
Sep 17 2018 06:05
I had to retype them
@Marmiz Thanks I knew that something was up. I'm ganna go look up unicode now lol
Claudio Restifo
@Marmiz
Sep 17 2018 06:08
it's just that in the challenge, in order for the page to look like that some char has to be escaped. So the final "html" you see on the page is not clean. There's some char in between that the browser (nor node) was not picking up
Supra01
@Supra01
Sep 17 2018 06:10
@bobsbotty @ezioda004 Thanks for your insights and help
@Marmiz Good to know! I was about to put out my hair
Bjorn van de Peut
@bjorno43
Sep 17 2018 06:19
@Supra01 @bobsbotty isn't a person, lol
Claudio Restifo
@Marmiz
Sep 17 2018 06:20
@bjorno43 until it became self-aware :tongue:
then it still won't be a person, but a menace! :skull:
bobsbotty
@bobsbotty
Sep 17 2018 06:20
Don't tempt me..
Bjorn van de Peut
@bjorno43
Sep 17 2018 06:21
Almost convincing, lol
Supra01
@Supra01
Sep 17 2018 06:26
Oops I meant @ezioda004 lol
pumpkinT
@pumpkinT
Sep 17 2018 07:16
Hi
Claudio Restifo
@Marmiz
Sep 17 2018 07:39
:wave:
Luis Lota
@LuisLota
Sep 17 2018 08:21
hi
Bjorn van de Peut
@bjorno43
Sep 17 2018 08:21
:wave:
Bjorn van de Peut
@bjorno43
Sep 17 2018 08:57
Just because I could, adding functions dynamicly in JS:
(function(){
    "use strict";
    var name = "CustomFunc";

    // Custom Actions
    function CustomAction ( id ) {
        var id = "This object has id: "+id;

        // Read only getter for id
        Object.defineProperty(this, "id", {get: function(){return id}})
    } 

    // Implement the new function
    var func = new Function("name", "action",
        " return function " + name + "(id){ "+
        // Prevent running in global scope
        " if(this === window) throw TypeError('Invalid constructor! try using new');" +
        " return Object.create(new action(id)); };"
    )(name, CustomAction);

    // Add function to the global scope
    Object.defineProperty(window, name, {value: func } )
})();

var n = 3;

// Create dynamic function
window["foo"+n] = new CustomFunc("moo");

foo3.i; // This object has id: moo
psyperl
@psyperl
Sep 17 2018 10:48
analysis paralysis is real
tarangwadekar
@tarangwadekar
Sep 17 2018 11:07
I think it is.
Kranti Nebhwani
@darkphotonKN
Sep 17 2018 12:55
@thekholm80 @ezioda004 hey guys, you guys know how we use import in react:
import axios from 'axios';
How do i that in a regular JS file without needing to compile it to a version of ES that the browser understands, as right now it doesnt recognize import. And for the life of me I can't find anything online that indicates a replacement for import. Even on MDN it just shows the various ways it can import without mentioning that browsers may not support it or replacements, and if I do it on the babel site to see what it gets compiled to its still using import but with a bunch of other random text that still won't work when I try it on my page as it won't recognize the first import keyword.
Aditya
@ezioda004
Sep 17 2018 13:04
@darkphotonKN ES6+ browsers support import, in the script tag you'll need type = "module"and then you can use import, also you'll need a server running
Luc Martin
@fmartin5
Sep 17 2018 13:08
@darkphotonKN Before using import, old libraries used dynamic script tag insertion, or even fetching js code via ajax and then passing it througheval
That was the dark times
Kranti Nebhwani
@darkphotonKN
Sep 17 2018 13:12
@ezioda004 @fmartin5 ah ok much appreciated!
psyperl
@psyperl
Sep 17 2018 13:14
/// only one property will be registered
const obj = {
 "somekeythatistoolongandynamicduringruntime" 
  : "somevalueiwant"}

const theValueIWant = obj[Object.keys(obj)[0]]
wonder if there is a better way
Aditya
@ezioda004
Sep 17 2018 13:15
@darkphotonKN Heres a good tutorial
Kranti Nebhwani
@darkphotonKN
Sep 17 2018 13:15
@ezioda004 exactly what i was looking for :thumbsup:
Aditya
@ezioda004
Sep 17 2018 13:16
@psyperl What are you trying to do?
psyperl
@psyperl
Sep 17 2018 13:17
@ezioda004 to get somevalueiwant
Aditya
@ezioda004
Sep 17 2018 13:18
Yeah that seems fine
Can also do
for (let key in obj){
  if (obj.hasOwnProperty(key)){
    obj[key]
  }
}
psyperl
@psyperl
Sep 17 2018 13:19
thanks yeah, and it works fine, but it looks messy.. i was wondering if there is a short way of doing it .. like using special syntax or some such
ah that's just me being pesky about the code .. such an unimportant question. whichever works i guess .. thanks @ezioda004
Aditya
@ezioda004
Sep 17 2018 13:26
I cant think of special syntax, Object.keys() is the way to go these days, in past that for loop was used.
Theres also Object.values() which will return values array, so you can do Object.values(obj)[0]; //somevalueiwant but objects are unordered and I'm always hesitant relying on fetching values like they are ordered
psyperl
@psyperl
Sep 17 2018 13:28
ahh nice Object.values(obj)[0] is much shorter, i will use that thanks @ezioda004
/// char length compare
obj[Object.keys(obj)[0]]
Object.values(obj)[0]
saving me from not writing the obj twice :D
Aditya
@ezioda004
Sep 17 2018 13:36
@psyperl I was referring to this, something to keep in mind
psyperl
@psyperl
Sep 17 2018 13:37
yes i am aware of that.. thanks for reminding me
there is guarantee that there will only be one value/property in this obj for this case so i am using it
psyperl
@psyperl
Sep 17 2018 13:43
another question.. is there a way to make a variable or function registered into the dev console?
Aditya
@ezioda004
Sep 17 2018 13:44
Registered as in?
psyperl
@psyperl
Sep 17 2018 13:44
for example.. when we type doc the dev console will give us an option for document
Screen Shot 2018-09-17 at 20.45.20.png
like the autocompletion in the picture
Aditya
@ezioda004
Sep 17 2018 13:46
Oh
psyperl
@psyperl
Sep 17 2018 13:46
but when i have my own var, obj or function.. it doesn't shows there
Aditya
@ezioda004
Sep 17 2018 13:47
Not sure, but in chrome it saves previous function/class declarations
Until you clear the cache
psyperl
@psyperl
Sep 17 2018 13:48
yeah i use some lib. and it shows in there.. so there must be a way..
Aditya
@ezioda004
Sep 17 2018 13:48
Are you using safari?
psyperl
@psyperl
Sep 17 2018 13:48
yes
Aditya
@ezioda004
Sep 17 2018 13:48
:apple: aint supported here
psyperl
@psyperl
Sep 17 2018 13:48
lol
Aditya
@ezioda004
Sep 17 2018 13:49
Chrome also have early evaluation, comes quite handy
psyperl
@psyperl
Sep 17 2018 13:49
are you on linux?
Aditya
@ezioda004
Sep 17 2018 13:50
Windows
psyperl
@psyperl
Sep 17 2018 13:50
yeah i don't usually use early evaluation version
Aditya
@ezioda004
Sep 17 2018 13:51
Its a cool feature, one of the reasons I really like quokka.js on VSC
psyperl
@psyperl
Sep 17 2018 13:51

https://support.apple.com/en-us/HT204416

Apple no longer offers Safari updates for Windows. Safari 5.1.7 for Windows was the last version made for Windows, and it is now outdated.

i just found that out wew
checked after you told me, i thought you were joking
Aditya
@ezioda004
Sep 17 2018 13:53
I'll nod along - totally didnt mean something else
psyperl
@psyperl
Sep 17 2018 13:53
yeah quokka looks handy
wei2333
@wei2333
Sep 17 2018 14:19
如何设置 href 的属性
May Kittens Devour Your Soul
@diomed
Sep 17 2018 14:58
欢迎,我们的中国领主
psyperl
@psyperl
Sep 17 2018 15:01
구글 번역 너무 멋지다
Kyle Holm
@thekholm80
Sep 17 2018 16:10
🙈🙉🙊
Smootimus
@Smootimus
Sep 17 2018 16:16
@ezioda004 Did you get your C stuff worked out?
Dev C++ might not be a bad idea, it does C on Windows
Afonso2011
@Afonso2011
Sep 17 2018 19:03
Hello guys
Noob question here :/
On the odin project, at this point "Step 3.3: Hooking our local repository to the remote repository"
It appears this error
"Rename from 'C:/Users/ASUS/AppData/Local/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/home/afonso2011/odin_on_rails/my_first_rails_app/.git/config.lock' to 'C:/Users/ASUS/AppData/Local/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/home/afonso2011/odin_on_rails/my_first_rails_app/.git/config' failed. Should I try again? (y/n)"
i dont know how to get past this step :(
Luc Martin
@fmartin5
Sep 17 2018 20:18
Maybe you don't have the right permissions ?
newmoon
@newmoon
Sep 17 2018 20:20
@Afonso2011 You may want to ask at https://gitter.im/TheOdinProject/theodinproject
Seems the file may be in use - or as Luc suggest, perhaps you aren't running the terminal/command prompt with admin privileges
Luc Martin
@fmartin5
Sep 17 2018 20:22
Yea
psyperl
@psyperl
Sep 17 2018 20:39
to get pass that step probably by pressing y or n :D
Kyle Holm
@thekholm80
Sep 17 2018 20:44
that's some fine detective work there @psyperl
psyperl
@psyperl
Sep 17 2018 20:46
:mag:
May Kittens Devour Your Soul
@diomed
Sep 17 2018 20:47
so glad we can finally hire women online to clean our screen
Kyle Holm
@thekholm80
Sep 17 2018 20:48
hire? she's cleaning mine for free
psyperl
@psyperl
Sep 17 2018 20:49
and took the screen with her?
psyperl
@psyperl
Sep 17 2018 21:15
my first attempt to make Promise today
Kyle Holm
@thekholm80
Sep 17 2018 21:15
how did it go?
psyperl
@psyperl
Sep 17 2018 21:15
almost giving up but retrying it again
Kyle Holm
@thekholm80
Sep 17 2018 21:16
i'd have to look it up because it's been a while, but i don't recall it being super hard
psyperl
@psyperl
Sep 17 2018 21:17
mdn doc is not really clear.. i had to search around for example before
Kyle Holm
@thekholm80
Sep 17 2018 21:18

something like

return new Promise((resolve, reject) => {
  if (this happens) {
    resolve(yay we win);
  } else {
    reject(poop);
  }
}

can't remember if resolve and reject are functions though - guess i should look it up lol

psyperl
@psyperl
Sep 17 2018 21:19
yeah .. but i am doing several checks
const firstCheck = x => 
  new Promise( (kept, broken) => x ? kept(x) : broken(x) )

firstCheck(someVal)
.then( ) // here i get confused to perform other check
Kyle Holm
@thekholm80
Sep 17 2018 21:22
oh, there you just do something with the resolved promise value
psyperl
@psyperl
Sep 17 2018 21:25
const firstCheck = x => 
  new Promise( (kept, broken) => x ? kept(x) : broken(x) )
const secondCheck = x =>
  new Promise( (kept, broken) => x ? kept(x) : broken(x) )

firstCheck(someVal)
 .then( x => secondCheck(x), x => console.error(x) )
 .then( x => console.log("passed") ) // would this work?
Kyle Holm
@thekholm80
Sep 17 2018 21:26
use catch() for error handling (rejected promises)
use then() for resolved promises
Christopher McCormack
@cmccormack
Sep 17 2018 21:26
is it data, err or err, data?
psyperl
@psyperl
Sep 17 2018 21:26
ah i thought catch is only if i use throw
data, err i think
Kyle Holm
@thekholm80
Sep 17 2018 21:26

i always did

func().then().catch();

in that order

not sure if it mattered
Bjorn van de Peut
@bjorno43
Sep 17 2018 21:27
There, fixed it:
return new Promise((resolve, eject) => {
  if (this happens) {
    resolve(yay we win);
  } else {
    eject(poop);
  }
}
Kyle Holm
@thekholm80
Sep 17 2018 21:27
lol ejecting poop isn't always a good idea
Bjorn van de Peut
@bjorno43
Sep 17 2018 21:27
:joy:
Christopher McCormack
@cmccormack
Sep 17 2018 21:29
Promise.prototype.then(onFulfilled, onRejected) if anyone cares
psyperl
@psyperl
Sep 17 2018 21:30
that's how i understood also yes
Christopher McCormack
@cmccormack
Sep 17 2018 21:30
catch does look nicer though :)
Kyle Holm
@thekholm80
Sep 17 2018 21:31
Promise.prototype.catch() is a thing, so is Promise.prototype.finally()
psyperl
@psyperl
Sep 17 2018 21:31
yeah i haven't played with both catch and finally yet
Kyle Holm
@thekholm80
Sep 17 2018 21:31
i've never used finally
psyperl
@psyperl
Sep 17 2018 21:31
so you've been making empty promises? :p
Kyle Holm
@thekholm80
Sep 17 2018 21:32
usually
psyperl
@psyperl
Sep 17 2018 21:33
ah i think i might have idea how i can use finally
Kyle Holm
@thekholm80
Sep 17 2018 21:34
i use async / await so i don't see how it would fit in my workflow
psyperl
@psyperl
Sep 17 2018 21:34
so my promises will check all resources / prepare resources .. when all resources ready .. i will process the resources on finally .. is that sounds ok?
oh no.. i haven't review async / await as well
Kyle Holm
@thekholm80
Sep 17 2018 21:35
have you checked out Promise.all()?
if i had, say, an array of urls i want to make GET requests to, and map over that array i'd use Promise.all(array.map(/* ajax magic */))
psyperl
@psyperl
Sep 17 2018 21:36
not yet
Kyle Holm
@thekholm80
Sep 17 2018 21:36
then it waits for all the promises to resolve before moving on
psyperl
@psyperl
Sep 17 2018 21:36
hmm
Kyle Holm
@thekholm80
Sep 17 2018 21:37
that one i've actually used before
psyperl
@psyperl
Sep 17 2018 21:37
moving on also with then ?
i would get confused what param will be passed to then
Kyle Holm
@thekholm80
Sep 17 2018 21:38
oh, i think it was something like const newArray = await Promise.all(oldArray.map(/* ajax magic */));
i'd have to look it up to be sure
psyperl
@psyperl
Sep 17 2018 21:39
hang on @thekholm80 i can't go that far yet.. i'll get confused otherwise haha
i'll try to get used to the most basic one first
Kyle Holm
@thekholm80
Sep 17 2018 21:39
lol sorry
psyperl
@psyperl
Sep 17 2018 21:40
but yeah i sort of see how that can be useful
one important question i have in mind though ... will it be wasteful if i use Promise just to check conditions as opposed to doing something asynchronous like network operation etc ?
Kyle Holm
@thekholm80
Sep 17 2018 21:42
i've seen it used on processes that just take some time
psyperl
@psyperl
Sep 17 2018 21:42
ok
Kyle Holm
@thekholm80
Sep 17 2018 21:42
like encryption
psyperl
@psyperl
Sep 17 2018 21:43
so it might take advantage of running it asynchoronously.. nice
in that Promis.all i can see how things can run in parallel .. but on normal one .. not sure how things work yet
psyperl
@psyperl
Sep 17 2018 21:57
thanks for the overview of the other related method though @thekholm80 , i'll catch up with those method soon
Kyle Holm
@thekholm80
Sep 17 2018 21:58
sorry i get excited. not trying to flood you with unneeded info
psyperl
@psyperl
Sep 17 2018 22:01
that makes me aware where/what i should seek next actually
Kyle Holm
@thekholm80
Sep 17 2018 22:03
seek the truth
psyperl
@psyperl
Sep 17 2018 22:03
:D
Smootimus
@Smootimus
Sep 17 2018 22:03
:)
'ello, 'ello!
Kyle Holm
@thekholm80
Sep 17 2018 22:03
hey smooty-smoot
Smootimus
@Smootimus
Sep 17 2018 22:03
Final week of class this quarter ya'll :D
How's it goin
Kyle Holm
@thekholm80
Sep 17 2018 22:04
good, good
playing video games
Smootimus
@Smootimus
Sep 17 2018 22:05
I feel ya, what ya playin'
I've been looking at a new video game, but I dunno
Shenzen I/O
It's on Steam
Kyle Holm
@thekholm80
Sep 17 2018 22:06
a buggy WoW emu, MoP
Smootimus
@Smootimus
Sep 17 2018 22:06
There's a TIS 100 from the same company
Hmm, Looking that up :D
Kyle Holm
@thekholm80
Sep 17 2018 22:06
oh, it's warmane
i'm on the MoP server
Smootimus
@Smootimus
Sep 17 2018 22:08
I do remember when that got released, actually
I haven't even thought about WoW since it came out and got popular
I played the original for like 30 mins maybe
Kyle Holm
@thekholm80
Sep 17 2018 22:09
every once in a while i'll get feeling nostalgic and try it again. never retail but some private servers are good for a laugh for a week or two
Smootimus
@Smootimus
Sep 17 2018 22:10
I been looking into this Godot game engine lately
Givin' it a consideration
Kyle Holm
@thekholm80
Sep 17 2018 22:10
i don't know what that means
Smootimus
@Smootimus
Sep 17 2018 22:11
What part? lol
Kyle Holm
@thekholm80
Sep 17 2018 22:11
the godot game engine
Smootimus
@Smootimus
Sep 17 2018 22:11
I guess it's a bit like Unity
Kyle Holm
@thekholm80
Sep 17 2018 22:11
why that and not unreal or unity?
Smootimus
@Smootimus
Sep 17 2018 22:12
I have Unity as well
But the guys I was considering doing a project with threw out the idea of using Godot
I've never even looked at it until then, heard it mentioned a time or two
So I've been doing some reading on it
Kyle Holm
@thekholm80
Sep 17 2018 22:12
could be fun
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:16
I've been interested in developing a 3D game for quite some time. Unfortunetely 3D modeling is out of my skillset. Free models usually look crap and buying models is way too expensive
Kyle Holm
@thekholm80
Sep 17 2018 22:17
that's been my big hold-up. i'm no artist
and i have no desire to become one
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:17
Ye same
Smootimus
@Smootimus
Sep 17 2018 22:17
Totally feel ya :D
Always been my weakness
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:18
I've tried it once. The idea isn't that complicated. But designing good looking models is rly hard. Not to mention animating them and having proper skeletons
Chase Sawyer
@shadowimmage
Sep 17 2018 22:19
I've tried 3D modeling - I'm not much of an artist either. Much better at mechanical objects, rather than anything organic
Kyle Holm
@thekholm80
Sep 17 2018 22:19
i made a donut in blender, that's about it for my 3d modeling
Smootimus
@Smootimus
Sep 17 2018 22:19
Hahaha
Was it an iced donut
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:20
I made Haunter from pokemon, lol
Smootimus
@Smootimus
Sep 17 2018 22:20
With sprinkles?
Haunter, nice
Kyle Holm
@thekholm80
Sep 17 2018 22:20
it was iced with sprinkles lol did you see that youtube lesson too?
Smootimus
@Smootimus
Sep 17 2018 22:20
I have Blender on my nice Laptop, never really done anything in it tho
But I can with this thing :D
I think I did hahah
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:20
Ye I did it in Blender as well
But there's also the time consuming issue. A single detailed model takes many hours to design. And that's just 1 model. You'll need plenty for a decent game
Though I did something fun once. You know the intro tutorial game "roll a ball" from some engines?
I made that multiplayer xD
Kyle Holm
@thekholm80
Sep 17 2018 22:23
lol
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:24
Ye it was quite challenging to do
Making a multiplayer game with Unity is quite easy. But giving each player its own camera object.. that's where it becomes difficult
I mean, instantiating a camera object for a player is doable. But Unity updates the latest camera object to each player. So everyone was continuesly looking through the eyes of the latest player, while still controlling their own ball
Turned out you had to check if the latest camera was owned by the current player or not. If not, stop the update
Kyle Holm
@thekholm80
Sep 17 2018 22:29
oh man, a whole fresh set of 'gotchas' to learn.
i should jump right on that
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:30
Ghehe. I had a lot of fun playing around with it though. Definitely worth it
Kyle Holm
@thekholm80
Sep 17 2018 22:30
i wonder if i'd regret not learning C++ before starting
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:31
I didn't regret it. Most engines allow development in JS or C# just fine
Smootimus
@Smootimus
Sep 17 2018 22:39
Right
Even this Godot has it's own scripting language
It's extremely Python like
Or you could use C# or C++
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:43
I'd use C# as I'm formilliar with it
Kyle Holm
@thekholm80
Sep 17 2018 22:43
i'd use html
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:44
Or I'll just let @bobsbotty do all the work
Is he still alive?
@bobsbotty help
Kyle Holm
@thekholm80
Sep 17 2018 22:45
RIP in peace
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:45
Guess not.. So much for Supervisor, lol
Hmm. Supervisor says it's running though..
Kyle Holm
@thekholm80
Sep 17 2018 22:46
@bobsbotty help
sometimes he ignores you, worth a shot
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:46
@bobsbotty
5 + 5
Smootimus
@Smootimus
Sep 17 2018 22:47
O.O
What it hosted on
Kyle Holm
@thekholm80
Sep 17 2018 22:48
php and broken dreams
Smootimus
@Smootimus
Sep 17 2018 22:48
lmao
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:49
It's hosted on my own server here at home
Kyle Holm
@thekholm80
Sep 17 2018 22:50
bob do you eat surstromming?
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:53
@bobsbotty help
bobsbotty
@bobsbotty
Sep 17 2018 22:53
@bjorno43 Available functions:
  • Parse Javascript code and output result (command: help javascript)
  • Do Javascript challenges (command: help challenges)
Smootimus
@Smootimus
Sep 17 2018 22:53
Aaaaay
Kyle Holm
@thekholm80
Sep 17 2018 22:53
@bobsbotty what is your purpose?
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:53
@thekholm80 I don't even know what that is..
Kyle Holm
@thekholm80
Sep 17 2018 22:54
fish
Smootimus
@Smootimus
Sep 17 2018 22:54
:O
You ahev to watch people eat it
On Youtube
*have
Kyle Holm
@thekholm80
Sep 17 2018 22:54
funny vids
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:55
lol
Alright, lets see
@bobsbotty help
bobsbotty
@bobsbotty
Sep 17 2018 22:55
@bjorno43 Available functions:
  • Parse Javascript code and output result (command: help javascript)
  • Do Javascript challenges (command: help challenges)
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:55
Cool so that works..
Kyle Holm
@thekholm80
Sep 17 2018 22:56
@Smootimus x
Bjorn van de Peut
@bjorno43
Sep 17 2018 22:57
I've implemented a kill timer so it restarts every 10 minutes. Seems PHP becomes unresponsive after 12 hours of running an inactive script
Kyle Holm
@thekholm80
Sep 17 2018 22:57
maybe he gets bored and starts surfing reddit?
that's what i do
Smootimus
@Smootimus
Sep 17 2018 22:57
Hahaha I had a feeling
Something was gonna jump out like that when I read the first frame
Bjorn van de Peut
@bjorno43
Sep 17 2018 23:01
Oh crap..
It's not PHP messing around
My server enters a sleep mode.. grmbl! :joy:
Kyle Holm
@thekholm80
Sep 17 2018 23:01
...
i remember my first computer
Bjorn van de Peut
@bjorno43
Sep 17 2018 23:11
Reading through the Godot docs I have to say, it seems a nice and easy to use engine
Smootimus
@Smootimus
Sep 17 2018 23:12
Yeah not too bad it seems
Looking forward to doing something in it :D
Bjorn van de Peut
@bjorno43
Sep 17 2018 23:13
Not to mention it's MIT licensed. So you truely own your games. Unlike Unreal where you'll have to pay 5% of your profits when they reach a certain limit
Smootimus
@Smootimus
Sep 17 2018 23:15
yeah that's nice, I hadn't even thought of that really
Kyle Holm
@thekholm80
Sep 17 2018 23:15
i'm kind of mixed on that
i think it's important to support the people that make the tools you use to make your money
but also, i like money
Bjorn van de Peut
@bjorno43
Sep 17 2018 23:16
True. But I believe that it's more fair to buy a product instead of giving up a percentage of your earnings
Kyle Holm
@thekholm80
Sep 17 2018 23:16
there is that
and a true purchase, not a monthly fee like adobe
Bjorn van de Peut
@bjorno43
Sep 17 2018 23:17
Exactly
Smootimus
@Smootimus
Sep 17 2018 23:18
Yeah, now THAT practice I find absolutely atrocious
Bjorn van de Peut
@bjorno43
Sep 17 2018 23:23
Take Ark Survival Evolved for example. It's made with Unreal. It currently has 9 million+ players. The game costs $60. That's $540 million. Take of most obvious costs like servers, devs etc etc and I'd say you still have a fair profit of $250 million. That's $12.5 million for Unreal. I don't care how good a program is. It's not worth that much!
psyperl
@psyperl
Sep 17 2018 23:33
$12.5m is nothing when you have $250m ?
Bjorn van de Peut
@bjorno43
Sep 17 2018 23:34
Perhaps not. But it's still way too much money for a game engine
psyperl
@psyperl
Sep 17 2018 23:34
well giving them $12.5m basically will give you extra benefit of back up and support from them
Bjorn van de Peut
@bjorno43
Sep 17 2018 23:35
I remember Unreal being a product that you could buy instead. It cost about $3000 if I remember correctly
For 12.5m they better be sitting on call 24/7 with a garantueed issue solving of 1 hour, lol
psyperl
@psyperl
Sep 17 2018 23:37
well, what would you do if you make game engine and someone give you 12.5m ?
Bjorn van de Peut
@bjorno43
Sep 17 2018 23:37
Give them the engine and retire somewhere warm and cosy :joy:
psyperl
@psyperl
Sep 17 2018 23:38
lol
psyperl
@psyperl
Sep 17 2018 23:47
this Promise is so funny.. i think i can put then everywhere
Bjorn van de Peut
@bjorno43
Sep 17 2018 23:49
I'm of to bed guys. Gn8!
psyperl
@psyperl
Sep 17 2018 23:49
night @bjorno43

imagine this case

const someFunc = x =>
  new Promise(someProcess)
    .then(anotherProcess)

i can refactor it easily with

const someFunc = x =>
  new Promise(someProcess)

someFunc()
  .then(anotherProcess)

i found it it funny/cool to be able to move the then anywhere we like