17th
Sep 2018
Kyle Holm
@thekholm80
Sep 17 2018 00:02 UTC
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 UTC
@thekholm80 ok sir.
Kyle Holm
@thekholm80
Sep 17 2018 00:12 UTC
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 UTC
idk who is patrick , i have to google it now.
Kyle Holm
@thekholm80
Sep 17 2018 00:13 UTC
he's an author
fiction
Karma Drukpa
@coderkarma
Sep 17 2018 00:14 UTC
I see. I have been trying to implement this arrow functions and higher order functions
Karma Drukpa
@coderkarma
Sep 17 2018 01:47 UTC
I need a help @bjorno43 @thekholm80 @Manish-Giri
Kyle Holm
@thekholm80
Sep 17 2018 01:51 UTC
@coderkarma which part are you stuck on?
Karma Drukpa
@coderkarma
Sep 17 2018 01:58 UTC
@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 UTC
@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 UTC
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 UTC
@kyle damn.. i never realize that sorry.
Kyle Holm
@thekholm80
Sep 17 2018 02:39 UTC
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
anyone done the helmet lessons by chance?
Bjorn van de Peut
@bjorno43
Sep 17 2018 02:55 UTC

@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 UTC
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 UTC
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 UTC
lol i was way wrong
Bjorn van de Peut
@bjorno43
Sep 17 2018 03:21 UTC
Ye I thought so. I can't get it fixed, lol
Kyle Holm
@thekholm80
Sep 17 2018 03:23 UTC
my eval is wrong i wasn't using num anywhere lol
Bjorn van de Peut
@bjorno43
Sep 17 2018 03:53 UTC
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
@ezioda004
Sep 17 2018 03:56 UTC
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 UTC
why coerce it to a string?
i feel like i'm missing something
@ezioda004
Sep 17 2018 04:02 UTC
Cause if index is 0, 0 || arr.length would return arr.length
Kyle Holm
@thekholm80
Sep 17 2018 04:02 UTC
oh right
because 0 is false
@ezioda004
Sep 17 2018 04:03 UTC
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 UTC
they should make a stopEverythingAndReturnThisValueFromThisMethod(value)
@ezioda004
Sep 17 2018 04:06 UTC
Time to write a proposal to TC39
Kyle Holm
@thekholm80
Sep 17 2018 04:06 UTC
like, reduce callback args could be (accumulator, reducer, index, copyOfArray, haltAndReturn)
@ezioda004
Sep 17 2018 04:06 UTC
I think its doable
Kyle Holm
@thekholm80
Sep 17 2018 04:09 UTC
but i guess that would be the same as arr[arr.findIndex(callback)]
i'm pretty sure it halts at the first match
@ezioda004
Sep 17 2018 04:10 UTC

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 UTC
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 UTC
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 } }, '');
@ezioda004
Sep 17 2018 04:24 UTC
@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 UTC
you're missing an argument
reduce() has 3 args (2 optional)
reduce(callback, initial, this)
@ezioda004
Sep 17 2018 04:28 UTC
a, c, i, arr
4 no?
Oh
Kyle Holm
@thekholm80
Sep 17 2018 04:28 UTC
4 for the callback
@ezioda004
Sep 17 2018 04:28 UTC
I dont think it takes this ie 3rd argument
Kyle Holm
@thekholm80
Sep 17 2018 04:29 UTC
oh weird
Bjorn van de Peut
@bjorno43
Sep 17 2018 04:29 UTC
You can kill reduce by using arr.splice(1) on evaluating a true condition
@ezioda004
Sep 17 2018 04:29 UTC
[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 UTC
Well technically you're not killing it. You're just removing the remaining elements
Kyle Holm
@thekholm80
Sep 17 2018 04:29 UTC
well what the crap am i thinking of?
@ezioda004
Sep 17 2018 04:30 UTC
Mutating the original array is a no-no in my book
Kyle Holm
@thekholm80
Sep 17 2018 04:30 UTC
oh, map()
@ezioda004
Sep 17 2018 04:31 UTC
Yeah, map, .filter and others have this
Kyle Holm
@thekholm80
Sep 17 2018 04:31 UTC
JS is dumb
i'm gonna learn PHP. at least it knows it's dumb
@ezioda004
Sep 17 2018 04:33 UTC
The original dumb and dumber
psyperl
@psyperl
Sep 17 2018 04:34 UTC
<?php
echo '<script>document.write("hello world");</script>';
?>
Bjorn van de Peut
@bjorno43
Sep 17 2018 04:36 UTC
<textarea name='php'></textarea>

<?php

eval($_POST['php']); ?> ^ I'm sure nothing can go wrong Supra01 @Supra01 Sep 17 2018 05:07 UTC 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 UTC @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 UTC @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 UTC @Supra01 which test is failing? :) Supra01 @Supra01 Sep 17 2018 05:14 UTC Yup Claudio Restifo @Marmiz Sep 17 2018 05:14 UTC which one... all of them? Bjorn van de Peut @bjorno43 Sep 17 2018 05:15 UTC 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 UTC @bjorno43 But when I run node it works. .... @Marmiz Only the last test passes Bjorn van de Peut @bjorno43 Sep 17 2018 05:19 UTC @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 UTC @bjorno43 The result of your Javascript code is: This%20%3C%20should%20be%20%3E%20encoded Claudio Restifo @Marmiz Sep 17 2018 05:22 UTC @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 UTC @bobsbotty encodeURIComponent("This < should be > encoded"); bobsbotty @bobsbotty Sep 17 2018 05:23 UTC @bjorno43 The result of your Javascript code is: This%20%3C%20should%20be%20%3E%20encoded psyperl @psyperl Sep 17 2018 05:28 UTC @bobsbotty btoa('check') bobsbotty @bobsbotty Sep 17 2018 05:28 UTC @psyperl There was an error with your Javascript code: V8Js::compileString():2: ReferenceError: btoa is not defined Aditya @ezioda004 Sep 17 2018 05:28 UTC @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 UTC i've never seen nested switch before.. is that even possible? Bjorn van de Peut @bjorno43 Sep 17 2018 05:32 UTC @bobsbotty 'Some < test " string >'.replace(/[\x26\x0A\<>'"]/g,function(r){return"&#"+r.charCodeAt(0)+";"}); bobsbotty @bobsbotty Sep 17 2018 05:32 UTC @bjorno43 The result of your Javascript code is: Some &#60; test &#34; string &#62; psyperl @psyperl Sep 17 2018 05:32 UTC i guess it's possible, maybe not practical Supra01 @Supra01 Sep 17 2018 05:33 UTC @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 UTC @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 UTC @bjorno43 The result of your Javascript code is: Some &lt; test &quot; string &apos; Supra01 @Supra01 Sep 17 2018 05:36 UTC @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. Claudio Restifo @Marmiz Sep 17 2018 05:48 UTC @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 UTC Claudio Restifo @Marmiz Sep 17 2018 05:51 UTC so your tests fails because it's not really &lt; but &(some unicode)lt; Supra01 @Supra01 Sep 17 2018 05:51 UTC 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 UTC @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 UTC @Supra01 updates? Supra01 @Supra01 Sep 17 2018 06:05 UTC @Marmiz THANKS!!!!! Claudio Restifo @Marmiz Sep 17 2018 06:05 UTC :+1: unicodes matters :sparkles: Supra01 @Supra01 Sep 17 2018 06:05 UTC 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 UTC 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 UTC @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 UTC @Supra01 @bobsbotty isn't a person, lol Claudio Restifo @Marmiz Sep 17 2018 06:20 UTC @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 UTC Don't tempt me.. Bjorn van de Peut @bjorno43 Sep 17 2018 06:21 UTC Almost convincing, lol Supra01 @Supra01 Sep 17 2018 06:26 UTC Oops I meant @ezioda004 lol pumpkinT @pumpkinT Sep 17 2018 07:16 UTC Hi Claudio Restifo @Marmiz Sep 17 2018 07:39 UTC :wave: Luis Lota @LuisLota Sep 17 2018 08:21 UTC hi Bjorn van de Peut @bjorno43 Sep 17 2018 08:21 UTC :wave: Bjorn van de Peut @bjorno43 Sep 17 2018 08:57 UTC 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 UTC analysis paralysis is real tarangwadekar @tarangwadekar Sep 17 2018 11:07 UTC I think it is. Kranti Nebhwani @darkphotonKN Sep 17 2018 12:55 UTC @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 UTC @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 UTC @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 UTC @ezioda004 @fmartin5 ah ok much appreciated! psyperl @psyperl Sep 17 2018 13:14 UTC /// 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 UTC @darkphotonKN Heres a good tutorial Kranti Nebhwani @darkphotonKN Sep 17 2018 13:15 UTC @ezioda004 exactly what i was looking for :thumbsup: Aditya @ezioda004 Sep 17 2018 13:16 UTC @psyperl What are you trying to do? psyperl @psyperl Sep 17 2018 13:17 UTC @ezioda004 to get somevalueiwant Aditya @ezioda004 Sep 17 2018 13:18 UTC 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 UTC 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 UTC 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 UTC 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 UTC @psyperl I was referring to this, something to keep in mind psyperl @psyperl Sep 17 2018 13:37 UTC 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 UTC another question.. is there a way to make a variable or function registered into the dev console? Aditya @ezioda004 Sep 17 2018 13:44 UTC Registered as in? psyperl @psyperl Sep 17 2018 13:44 UTC for example.. when we type doc the dev console will give us an option for document like the autocompletion in the picture Aditya @ezioda004 Sep 17 2018 13:46 UTC Oh psyperl @psyperl Sep 17 2018 13:46 UTC but when i have my own var, obj or function.. it doesn't shows there Aditya @ezioda004 Sep 17 2018 13:47 UTC Not sure, but in chrome it saves previous function/class declarations Until you clear the cache psyperl @psyperl Sep 17 2018 13:48 UTC yeah i use some lib. and it shows in there.. so there must be a way.. Aditya @ezioda004 Sep 17 2018 13:48 UTC Are you using safari? psyperl @psyperl Sep 17 2018 13:48 UTC yes Aditya @ezioda004 Sep 17 2018 13:48 UTC :apple: aint supported here psyperl @psyperl Sep 17 2018 13:48 UTC lol Aditya @ezioda004 Sep 17 2018 13:49 UTC Chrome also have early evaluation, comes quite handy psyperl @psyperl Sep 17 2018 13:49 UTC are you on linux? Aditya @ezioda004 Sep 17 2018 13:50 UTC Windows psyperl @psyperl Sep 17 2018 13:50 UTC yeah i don't usually use early evaluation version Aditya @ezioda004 Sep 17 2018 13:51 UTC Its a cool feature, one of the reasons I really like quokka.js on VSC psyperl @psyperl Sep 17 2018 13:51 UTC 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 UTC I'll nod along - totally didnt mean something else psyperl @psyperl Sep 17 2018 13:53 UTC yeah quokka looks handy wei2333 @wei2333 Sep 17 2018 14:19 UTC å¦‚ä½•è®¾ç½® href çš„å±žæ€§ May Kittens Devour Your Soul @diomed Sep 17 2018 14:58 UTC æ¬¢è¿Žï¼Œæˆ‘ä»¬çš„ä¸­å›½é¢†ä¸» psyperl @psyperl Sep 17 2018 15:01 UTC êµ¬ê¸€ ë²ˆì—­ ë„ˆë¬´ ë©‹ì§€ë‹¤ Kyle Holm @thekholm80 Sep 17 2018 16:10 UTC ðŸ™ˆðŸ™‰ðŸ™Š Smootimus @Smootimus Sep 17 2018 16:16 UTC @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 UTC 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 UTC Maybe you don't have the right permissions ? newmoon @newmoon Sep 17 2018 20:20 UTC @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 UTC Yea psyperl @psyperl Sep 17 2018 20:39 UTC to get pass that step probably by pressing y or n :D Kyle Holm @thekholm80 Sep 17 2018 20:44 UTC that's some fine detective work there @psyperl psyperl @psyperl Sep 17 2018 20:46 UTC :mag: May Kittens Devour Your Soul @diomed Sep 17 2018 20:47 UTC so glad we can finally hire women online to clean our screen Kyle Holm @thekholm80 Sep 17 2018 20:48 UTC hire? she's cleaning mine for free psyperl @psyperl Sep 17 2018 20:49 UTC and took the screen with her? psyperl @psyperl Sep 17 2018 21:15 UTC my first attempt to make Promise today Kyle Holm @thekholm80 Sep 17 2018 21:15 UTC how did it go? psyperl @psyperl Sep 17 2018 21:15 UTC almost giving up but retrying it again Kyle Holm @thekholm80 Sep 17 2018 21:16 UTC 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 UTC mdn doc is not really clear.. i had to search around for example before Kyle Holm @thekholm80 Sep 17 2018 21:18 UTC 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 UTC 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 UTC oh, there you just do something with the resolved promise value psyperl @psyperl Sep 17 2018 21:25 UTC 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 UTC use catch() for error handling (rejected promises) use then() for resolved promises Christopher McCormack @cmccormack Sep 17 2018 21:26 UTC is it data, err or err, data? psyperl @psyperl Sep 17 2018 21:26 UTC ah i thought catch is only if i use throw data, err i think Kyle Holm @thekholm80 Sep 17 2018 21:26 UTC i always did func().then().catch(); in that order not sure if it mattered Bjorn van de Peut @bjorno43 Sep 17 2018 21:27 UTC 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 UTC lol ejecting poop isn't always a good idea Bjorn van de Peut @bjorno43 Sep 17 2018 21:27 UTC :joy: Christopher McCormack @cmccormack Sep 17 2018 21:29 UTC Promise.prototype.then(onFulfilled, onRejected) if anyone cares psyperl @psyperl Sep 17 2018 21:30 UTC that's how i understood also yes Christopher McCormack @cmccormack Sep 17 2018 21:30 UTC catch does look nicer though :) Kyle Holm @thekholm80 Sep 17 2018 21:31 UTC Promise.prototype.catch() is a thing, so is Promise.prototype.finally() psyperl @psyperl Sep 17 2018 21:31 UTC yeah i haven't played with both catch and finally yet Kyle Holm @thekholm80 Sep 17 2018 21:31 UTC i've never used finally psyperl @psyperl Sep 17 2018 21:31 UTC so you've been making empty promises? :p Kyle Holm @thekholm80 Sep 17 2018 21:32 UTC usually psyperl @psyperl Sep 17 2018 21:33 UTC ah i think i might have idea how i can use finally Kyle Holm @thekholm80 Sep 17 2018 21:34 UTC i use async / await so i don't see how it would fit in my workflow psyperl @psyperl Sep 17 2018 21:34 UTC 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 UTC 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 UTC not yet Kyle Holm @thekholm80 Sep 17 2018 21:36 UTC then it waits for all the promises to resolve before moving on psyperl @psyperl Sep 17 2018 21:36 UTC hmm Kyle Holm @thekholm80 Sep 17 2018 21:37 UTC that one i've actually used before psyperl @psyperl Sep 17 2018 21:37 UTC moving on also with then ? i would get confused what param will be passed to then Kyle Holm @thekholm80 Sep 17 2018 21:38 UTC 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 UTC 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 UTC lol sorry psyperl @psyperl Sep 17 2018 21:40 UTC 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 UTC i've seen it used on processes that just take some time psyperl @psyperl Sep 17 2018 21:42 UTC ok Kyle Holm @thekholm80 Sep 17 2018 21:42 UTC like encryption psyperl @psyperl Sep 17 2018 21:43 UTC 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 UTC 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 UTC sorry i get excited. not trying to flood you with unneeded info psyperl @psyperl Sep 17 2018 22:01 UTC that makes me aware where/what i should seek next actually Kyle Holm @thekholm80 Sep 17 2018 22:03 UTC seek the truth psyperl @psyperl Sep 17 2018 22:03 UTC :D Smootimus @Smootimus Sep 17 2018 22:03 UTC :) 'ello, 'ello! Kyle Holm @thekholm80 Sep 17 2018 22:03 UTC hey smooty-smoot Smootimus @Smootimus Sep 17 2018 22:03 UTC Final week of class this quarter ya'll :D How's it goin Kyle Holm @thekholm80 Sep 17 2018 22:04 UTC good, good playing video games Smootimus @Smootimus Sep 17 2018 22:05 UTC 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 UTC a buggy WoW emu, MoP Smootimus @Smootimus Sep 17 2018 22:06 UTC There's a TIS 100 from the same company Hmm, Looking that up :D Kyle Holm @thekholm80 Sep 17 2018 22:06 UTC oh, it's warmane i'm on the MoP server Smootimus @Smootimus Sep 17 2018 22:08 UTC 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 UTC 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 UTC I been looking into this Godot game engine lately Givin' it a consideration Kyle Holm @thekholm80 Sep 17 2018 22:10 UTC i don't know what that means Smootimus @Smootimus Sep 17 2018 22:11 UTC What part? lol Kyle Holm @thekholm80 Sep 17 2018 22:11 UTC the godot game engine Smootimus @Smootimus Sep 17 2018 22:11 UTC I guess it's a bit like Unity Kyle Holm @thekholm80 Sep 17 2018 22:11 UTC why that and not unreal or unity? Smootimus @Smootimus Sep 17 2018 22:12 UTC 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 UTC could be fun Bjorn van de Peut @bjorno43 Sep 17 2018 22:16 UTC 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 UTC 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 UTC Ye same Smootimus @Smootimus Sep 17 2018 22:17 UTC Totally feel ya :D Always been my weakness Bjorn van de Peut @bjorno43 Sep 17 2018 22:18 UTC 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 UTC 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 UTC i made a donut in blender, that's about it for my 3d modeling Smootimus @Smootimus Sep 17 2018 22:19 UTC Hahaha Was it an iced donut Bjorn van de Peut @bjorno43 Sep 17 2018 22:20 UTC I made Haunter from pokemon, lol Smootimus @Smootimus Sep 17 2018 22:20 UTC With sprinkles? Haunter, nice Kyle Holm @thekholm80 Sep 17 2018 22:20 UTC it was iced with sprinkles lol did you see that youtube lesson too? Smootimus @Smootimus Sep 17 2018 22:20 UTC 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 UTC 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 UTC lol Bjorn van de Peut @bjorno43 Sep 17 2018 22:24 UTC 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 UTC 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 UTC Ghehe. I had a lot of fun playing around with it though. Definitely worth it Kyle Holm @thekholm80 Sep 17 2018 22:30 UTC i wonder if i'd regret not learning C++ before starting Bjorn van de Peut @bjorno43 Sep 17 2018 22:31 UTC I didn't regret it. Most engines allow development in JS or C# just fine Smootimus @Smootimus Sep 17 2018 22:39 UTC 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 UTC I'd use C# as I'm formilliar with it Kyle Holm @thekholm80 Sep 17 2018 22:43 UTC i'd use html Bjorn van de Peut @bjorno43 Sep 17 2018 22:44 UTC Or I'll just let @bobsbotty do all the work Is he still alive? @bobsbotty help Kyle Holm @thekholm80 Sep 17 2018 22:45 UTC RIP in peace Bjorn van de Peut @bjorno43 Sep 17 2018 22:45 UTC Guess not.. So much for Supervisor, lol Hmm. Supervisor says it's running though.. Kyle Holm @thekholm80 Sep 17 2018 22:46 UTC @bobsbotty help sometimes he ignores you, worth a shot Bjorn van de Peut @bjorno43 Sep 17 2018 22:46 UTC @bobsbotty 5 + 5 Smootimus @Smootimus Sep 17 2018 22:47 UTC O.O What it hosted on Kyle Holm @thekholm80 Sep 17 2018 22:48 UTC php and broken dreams Smootimus @Smootimus Sep 17 2018 22:48 UTC lmao Bjorn van de Peut @bjorno43 Sep 17 2018 22:49 UTC It's hosted on my own server here at home Kyle Holm @thekholm80 Sep 17 2018 22:50 UTC bob do you eat surstromming? Bjorn van de Peut @bjorno43 Sep 17 2018 22:53 UTC @bobsbotty help bobsbotty @bobsbotty Sep 17 2018 22:53 UTC @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 UTC Aaaaay Kyle Holm @thekholm80 Sep 17 2018 22:53 UTC @bobsbotty what is your purpose? Bjorn van de Peut @bjorno43 Sep 17 2018 22:53 UTC @thekholm80 I don't even know what that is.. Kyle Holm @thekholm80 Sep 17 2018 22:54 UTC fish Smootimus @Smootimus Sep 17 2018 22:54 UTC :O You ahev to watch people eat it On Youtube *have Kyle Holm @thekholm80 Sep 17 2018 22:54 UTC funny vids Bjorn van de Peut @bjorno43 Sep 17 2018 22:55 UTC lol Alright, lets see @bobsbotty help bobsbotty @bobsbotty Sep 17 2018 22:55 UTC @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 UTC Cool so that works.. Kyle Holm @thekholm80 Sep 17 2018 22:56 UTC @Smootimus x Bjorn van de Peut @bjorno43 Sep 17 2018 22:57 UTC 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 UTC maybe he gets bored and starts surfing reddit? that's what i do Smootimus @Smootimus Sep 17 2018 22:57 UTC 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 UTC Oh crap.. It's not PHP messing around My server enters a sleep mode.. grmbl! :joy: Kyle Holm @thekholm80 Sep 17 2018 23:01 UTC ... i remember my first computer Bjorn van de Peut @bjorno43 Sep 17 2018 23:11 UTC 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 UTC Yeah not too bad it seems Looking forward to doing something in it :D Bjorn van de Peut @bjorno43 Sep 17 2018 23:13 UTC 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 UTC yeah that's nice, I hadn't even thought of that really Kyle Holm @thekholm80 Sep 17 2018 23:15 UTC 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 UTC 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 UTC there is that and a true purchase, not a monthly fee like adobe Bjorn van de Peut @bjorno43 Sep 17 2018 23:17 UTC Exactly Smootimus @Smootimus Sep 17 2018 23:18 UTC Yeah, now THAT practice I find absolutely atrocious Bjorn van de Peut @bjorno43 Sep 17 2018 23:23 UTC 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 UTC$12.5m is nothing when you have $250m ? Bjorn van de Peut @bjorno43 Sep 17 2018 23:34 UTC Perhaps not. But it's still way too much money for a game engine psyperl @psyperl Sep 17 2018 23:34 UTC 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 UTC
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 UTC
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 UTC
Give them the engine and retire somewhere warm and cosy :joy:
psyperl
@psyperl
Sep 17 2018 23:38 UTC
lol
psyperl
@psyperl
Sep 17 2018 23:47 UTC
this Promise is so funny.. i think i can put then everywhere
Bjorn van de Peut
@bjorno43
Sep 17 2018 23:49 UTC
I'm of to bed guys. Gn8!
psyperl
@psyperl
Sep 17 2018 23:49 UTC
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