« first day (3404 days earlier)      last day (1769 days later) » 
03:00 - 16:0016:00 - 00:00

16:13
hey guys, is it possible to get the "hex" portion of an 0x integer in JS
as a string
so...

0xff should output 255 right?. I want it to output "ff"
but 0xff isnt a string, I cant just concat and remove 0x
Ray
Ray
(255).toString(16)
const v=255; v.toString(16);
??
Thats not FF
I need the hex portion
so I can put them together to make a css-usable hex
You need to read the page a bit more: toString takes an argument that states the base.
16:17
so like:

I need to merge 0xff 0xff and 0xff

and get #ffffff
oh..
Ray
Ray
I'm pretty sure what we stated should be fine
don't forget the #, i remember making that mistake when doing css stuff
I figured it out, thanks
for some reason
I thought it was outputting 16
I am -20 in my eyes, but comon
keep in mind, 0x0 up to 0xF is still a thing
merging 255, 255, 0 would end up with #ffff0 (ff + ff + 0)
which is not a valid code
3, 4, 6 or 8 hex characters are valid codes
5 is not
Jesus lord help me...
if (cD.curRed == 0xff && cD.curGreen < 0xff && cD.curBlue == 0x00) {
   cD.curGreen += rate;
  } else if (cD.curRed > 0x00 && cD.curGreen == 0xff && cD.curBlue < 0xff) {
   cD.curRed -= rate;
  } else if (cD.curRed == 0x00 && cD.curGreen == 0xff && cD.curBlue < 0xff) {
   cD.curBlue += rate;
  } else if (cD.curRed == 0x00 && cD.curGreen > 0x00 && cD.curBlue == 0xff) {
   cD.curGreen -= rate;
  } else if (cD.curRed < 0xff && cD.curGreen == 0x00 && cD.curBlue == 0xff) {
   cD.curRed += rate;
  } else if (cD.curRed == 0xff && cD.curGreen == 0x00 && cD.curBlue > 0x00) {
(see full text)
ey yi yi
It works, but gosh is that one crazy if statement
not just one
it looks like it should be refactored
16:29
Im inexperienced, not really sure how I could
I have 3 absolute and relative checks for each one
me neither, because I dont know the goal
Ray
Ray
you know you can just use rgb css right?
Nope, it HAS to be hex XD
its for a personal project
Ray
Ray
background-color: rgb(255,255,0);
rgb is too easy
subtract and add
Ray
Ray
16:30
padStart() ?
but this one was more fun to make
ye, why make it yourself easy if you also can go for the hard way
calculating hex is interesting to me
I see no reason why calculating hex would be of any interest
Ive just learned of this recently
@HéctorÁlvarez Its something new, let me enjoy it, its been a while since ive seen something interestingly new in js
atleast that I didnt know about before
16:32
it is on an abstraction level that I dont give a floop about
it must work for me, not me for it
same as me not wanting to write an int to string converter
or a number rounder
or an array implementation
I am sure someone would find it interesting, but I would generally say that as a junior programmer, you should not
it could make programming a lot easier, and you could focus on actual features, rather than behind the scenes interesting looking code
until, behind the scenes interesting looking code is your business requirement
guys how to "translate" return Object.entries(o).reduce((o, [k, v]) => v >= maxN ? { ...o, [k]: v } : o, {}); to OLD js code (without arrow function)?
17:03
Hey Im curious on this, I was trying to make an animated gradient maker for fun, and I noticed my drawing line is actually not staying in its position
like, its acting as if I was using clearRect or fillRect to the width and height
clearing the canvas, but im not.
also @HéctorÁlvarez that thing earlier is not functional
it does convert Some of them correctly
but a lot of them when at 0 or less then 50, the numbers only show the whole int, not the 0, so I get wierd outputs in the console, not full hex color codes
"#" + cD.curRed.toString(16) + cD.curGreen.toString(16) + cD.curBlue.toString(16)
Im guessing toString with the 16 bit thing is removing the extra Zeros
making empty spaces
is there any bug in my code ??
@EpycDev Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
@EpycDev Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
1 message moved to Trash can
i want to retrieve this jSON data into my datatable
jesus christ dude
Idk what just happened
the chat crashed when jamesbot chatted lol
froze the tab and lost connection lolus
$('#example').dataTable( {
      "ajax": {
        "url": "https://script.google.com/macros/s/AKfycbyPmBNMDLfKx2bAsQgeWLqtJxIWagJm3uUq4vzjpx6lsF7HMxU/exec",
        "type": "POST"
      }
    });
my datatable show 0 results
17:37
Im not using clearRect or fillRect on my whole canvas... why isnt my canvas keeping the last thing I drew?? codepen.io/SkylerSpark/pen/qBddqXj?editors=1010
Im trying to draw a gradient
its not working the way I want it to
oh crap I figured it out...
I was setting the canvas width and height.. that was clearing it
FFS
rlly
Well... I calculated hex and made a frickin RAINBOW... codepen.io/SkylerSpark/pen/qBddqXj?editors=1010
booored
18:11
Even more bored:
user8729657
What does signing an Intellectual Property agreement mean? Does he own all the idea I create for the company?
@OvieTrix Well, it depends
youd have to talk to us about whats actually written in the agreement.
Sometimes the agreement gives the company ownership over the program so you can sue them or claim the program later on
Imagine if a programmer did contract work: and then left the company
years later, many updates, the program is earning millions
they could sue
and Kaboom, money money money
or something like that
that's a really long way of saying "Yes"
18:24
when you write code for a company, 100% of it belongs to the company, not you
Thats what contract work is
they pay you for your work
@OvieTrix as long as they are paying you, you can do the contract no probs
If you dislike that idea, you dont have to take the job
you sign over your code for contract or salaried positions alike
you'll be hard pressed to find an employer that won't require it
^
I dont care about claiming my code ownership because Im too shitty at it still
guys how to "translate":
18:27
return Object.entries(o).reduce((o, [k, v]) => v >= maxN ? { ...o, [k]: v } : o, {});
to OLD js code (without arrow function)?
What is this even for?
We need some info
cant just take mystery code and make it work
you can
oh the arrow expression?
thats simple
translate it to OLD js
i dont understand the {} part
@Proo1931 you need to define "Old JS", what does it need to be compatible with
18:28
function(o, [k, v]) {
 //blah
}
its not old
before es6
Its called a function
it is not working I tried that
Oh wait
its a more complicated one, one sec
in that case you'll probably need to refactor out the reduce too
18:29
	return Object.entries(o).reduce(function(o, [k, v])
	{
		return v >= maxN ? { ...o, [k]: v } : o, {};
	});
is not working
the part {} is somehow different
damn.. um, that is a strange looking expression
I actually dont know
yeaa :)
also, im curious, are you a non-english speaker?
it is Conditional Operator (ternary operator)
yes I'm
ok, I was just curious. As for the code, Im not that experienced
18:30
return Object
  .entries(o)
  .reduce((acc, [k, v]) =>
          v >= maxN
          	? { ...acc, [k]: v }
          	: acc
          , {}
         );
IF ? TRUE : FALSE
Well yes, I know that, its a simplified ternary if statement
But the rest is just a little strange synta
this code is basically just a gate for what entries from the source object can get into the target object
if the source object looks like {a: 2, b: 4, c: 6} and maxN is 4, this code will return {b: 4, c: 6}
yes
you are right
how on I have this somwhere
here it is:
function maxValues(o, n) {
  	var values = Object.values(o).sort(function(a, b)
  	{
  		return b - a;
  	});
  	if (values.length <= n) return o;
  	var maxN = values[n - 1];
	return Object.entries(o).reduce((o, [k, v]) => v >= maxN ? { ...o, [k]: v } : o, {});
}
var a = maxValues({
  a: 5,
  b: 10,
  c: 15,
  d: 20,
  e: 20,
  f: 25
}, 3);
console.log(a);
I'm gonna ignore the rest of that for now
18:36
return Object
.entries(o)
.reduce((o, [k, v]) =>
v >= maxN
? { ...0, [k]: v }
: 0
, {}
);
is not working
it was not meant to be a solution
anyway I need to translate return Object.entries(o).reduce((o, [k, v]) => v >= maxN ? { ...o, [k]: v } : o, {});
to OLD js
@Proo1931 Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
is not working either...
18:37
@forresthopkinsa ok,no problem
	return Object.entries(o).reduce(function(o, [k, v])
	{
		return v >= maxN ? { ...o, [k]: v } : o, {};
	});
let oldObj = o;
let newObj = {};
for (var key in oldObj) {
  if (oldObj[key] >= maxN) {
    newObj[key] = oldObj[key];
  }
}
give that a shot
user8729657
Thanks for clearing that up @TaylorS !
np.
Aww, just got the bad news, one of my questions got downvoted for being opinion based on a documentation question. Im quesiton banned again
time for half a year of sadness and depression
lolrip
Ive been dealing with it for 3 years
I can wait more
@forresthopkinsa no go :(
give me something to work with, what's the error
18:45
function maxValues(o, n) {
  	var values = Object.values(o).sort(function(a, b)
  	{
  		return b - a;
  	});
  	if (values.length <= n) return o;
  	var maxN = values[n - 1];

  	//return Object.entries(o).reduce((o, [k, v]) => v >= maxN ? { ...o, [k]: v } : o, {});

	return Object
  	.entries(o)
  	.reduce((o, [k, v]) =>
          v >= maxN
          	? { ...o, [k]: v }
          	: o
          , {}
   	);



}
var a = maxValues({
  a: 5,
  b: 10,
  c: 15,
  d: 20,
  e: 20,
  f: 25
}, 3);
console.log(a);
(see full text)
this is working
good
help me change:
 v >= maxN
  	? { ...o, [k]: v }
  	: o
  , {}
so it can work with function()
return Object
.entries(o)
.reduce(function(o, [k, v]) =>
v >= maxN
? { ...o, [k]: v }
: o
, {}
);
function maxValues(o, n) {
  	var values = Object.values(o).sort(function(a, b)
  	{
  		return b - a;
  	});
  	if (values.length <= n) return o;
  	var maxN = values[n - 1];

  	//return Object.entries(o).reduce((o, [k, v]) => v >= maxN ? { ...o, [k]: v } : o, {});


	return Object
  	.entries(o)
  	.reduce(function(o, [k, v])
  	{
          return v >= maxN
          	? { ...o, [k]: v }
          	: o
          , {}
   	});



}
var a = maxValues({
  a: 5,
  b: 10,
  c: 15,
  d: 20,
  e: 20,
(see full text)
is not working
how can I delete own post ?
don't ask people to write your code for you
learn javascript before writing javascript
18:49
@forresthopkinsa atleast we dont have those kinds that change values and colors in HTML5 games and call them their own
i just don't know why this code is not working in an old style
back when I first started doing javascript back in 6th grade, I saw a kid mocking me, he got a snake html5 game and copied the frame's html... and then he looked for a color and changed it to "yellow"
(before ES6)
and I was like... rlly bruh
and he was like "I built a game first!" but i told him it was probably off coolmathgames
Good old 6th grade..
18:51
@Proo1931 Why do you need to run it "before ES6"
Proo... Dont tell me.. ARE YOU RUNNING IT IN INTERNET EXPLORER
lol
it is just for learning
no :)
the code is working fine, but I want to experiment a little bit
Okay. Learn modern javascript.
Well, if you dont know how to fix it, I would suggest starting with something simpler...
like... how a function works
and I did everything, but only this problem gives me hedake
18:52
Don't downgrade the code so you can understand it
Understand it as it is
learn the difference between function lolName() {} and () => {}
why?
sometimes this syntecis sugar is braindamege for me
4
*syntetic
The whole language will be "braindamege" until you learn it
to really understand the language you need to REALLY understand it
what if you get old code to make changes in it?
"arr.reduce(callback( accumulator, currentValue[, index[, array]] )[, initialValue])"
this is "old code":
16 mins ago, by forresthopkinsa
let oldObj = o;
let newObj = {};
for (var key in oldObj) {
  if (oldObj[key] >= maxN) {
    newObj[key] = oldObj[key];
  }
}
but you couldn't get that to work either
I don't know if the code is right but you didn't even work with it
The bottom line is that to learn, you have to stop asking other people to do the work for you, you'll never get anywhere that way
18:55
I did try it ofcouse
Bang your head against the problem until you solve it
I did that amny times
its good idea
but not in this example
This example is not really that complicated
If you understand reducers then you'll understand your code
Im sorry, I know this was just a typing mistake, but I cant help but say that was amazingly funny
sometimes this syntecis sugar is braindamege for me
my for...in loop is functionally identical to the reducer you posted
Do some research on reducers and keep reading about them until you understand them
And then come back to this code
18:58
ok
gonna test it more
thanks for guildance
Goin home today, going to get windows 10 on a fresh new computer
its got an RTX gpu
Im excited :D
4 YEARS Ive waited lol
well, we built the computer 2 months ago, but due to a problem in the bios version IN BOTH OF THE MOTHERBOARDS we ordered (couldnt return the old one) we had to return the whole computer and FINALLY they fixed it
and we get it back yesterday, built it, it worked perfectly
well, unfortunately we spent a lot of money, and have an extra motherboard and cpu for it, so my dad will probably build himself or my sis one next (probably next year)
If I extend the Array class (class Something extends Array), how do I access the items in the array object I created?
const someArray = new Something();
someArray.push("text");
someArray.items // something like this?
oh, interesting
god damn it I still dont get it why I need to use:
function maxValues(o, n) {
  	var values = Object.values(o).sort(function(a, b)
  	{
  		return b - a;
  	});
  	if (values.length <= n) return o;
  	var maxN = values[n - 1];

  	//return Object.entries(o).reduce((o, [k, v]) => v >= maxN ? { ...o, [k]: v } : o, {});

	var oldObj = o;
	var newObj = {};
	for (var key in oldObj)
	{
	  if (oldObj[key] >= maxN)
	  {
	    newObj[key] = oldObj[key];
	  }
	}
	return newObj;

}
var a = maxValues({
  a: 5,
  b: 10,
  c: 15,
  d: 20,
  e: 20,
  f: 25
}, 3);
(see full text)
and I can't use old function()
which is perfectly normal inside reduce as callback
@forresthopkinsa can I ask you something via mail?
what? just post here, someone else might be able to help you better than I can anyway
@Proo1931 you'll never get anywhere if you don't say what's going wrong
"it's not working" means absolutely nothing
yea its just about reduce - I want to be sure how it works - here probably all know it already. prostyler@protonmail.com this is my mail, if you can write something I will rtie back the proiblem
	return Object.entries(o).reduce(function(o, [k, v])
	{
		return v >= maxN ? { ...o, [k]: v } : o, {};});
I dont understand why this function() is not working.
I'm sorry but I'm not gonna email, I'm just hopping into this screen when I can, post your problem in here
3 mins ago, by forresthopkinsa
"it's not working" means absolutely nothing
19:24
ok just a sec
19:45
CODE:
var items = [{a : 'val1', b : 'val2', c : 'val3', d : 'val4'}];

function test(array) {
  var str = 'TEST: there is NO v1, there is val2, but there is NO v3, v4 !!!';

  array.forEach(function(item) { // jest tylko 1 item - obiekt
    if (Object.values(item).reduce(function(accumulator, currentDataValue) // [val1, val2, val3, val4]
    {
      console.log('currentDataValue: ' + currentDataValue);
      console.log('+');
      console.log('accumulator: ' + accumulator);
      console.log('==================');
(see full text)
DESCRIPTION:
forEach is run only ONCE - cause there is ONE item in an array (object). IF is run >>>ONE<<< time, cause there are 4 object properties in array item but they are 'reduced' INSIDE IF.
We did NOT put(pass) initialValue so the accumulator (previousValue) is set as the first (val1) property of the object (item inside array), and the currentDataValue is set as the second (val2) property of the object.
reduce give us >>>THREE<<< iterations for array [look at 2@2] - so return gives us back:
(see full text)
20:05
i'm building a chat, i get user input this way: string = $('textarea').val(), then i append it to html, i want to prevent xss, replace <> is enough? I'm using this function:
function sanitize(string){
    const map = {
        '<': '&lt;',
        '>': '&gt;'
    };
    return string.replace(/[<>]/ig, (match)=>(map[match]));
}

string = sanitize($('textarea').val());
better off just using innerText/text()
as per OWASP
For example if you want to use user input to write in a div tag element don’t use innerHtml, instead use innerText or textContent. This will solve the problem, and it is the right way to re-mediate DOM based XSS vulnerabilities.
user8729657
20:19
@JBis, You respect POTUS? "Yeah, I respect him much more for doing that."
no, Romney
user8729657
Aye!
@JBis i also need to append some html, so i would need to append the html first then i get the element and use text()? Or there's a better way?
can you tell me why replacing <> is not enough?
@boss I would use document.createElement and then .innerText and then ammend that element.
18
A: Cross site scripting when the greater than and less than signs are escaped?

baordogOh yes it is! Consider this HTML: <a href="{{str}}"> and consider an input like: " onmouseover="alert('GOTCHA')" You get the picture. If your javascript is being injected within a tag then you don't need the angle brackets. I borrowed this off this similar S/O post: https://stackoverf...

20:34
@boss a proper html encode/decode should be sufficient
because that is... their entire purpose
although, different escaping rules do apply per location in the html
text between tags dont need their quotes escaped for example
while they definitely have to be escaped when placed in an attribute
Hi sup guys, i am going code blind any one on line to lend a hand
@deephect Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
postman test pm.expect(obj.hidden.notEquals).to.eql(data['Valuecon']);});} - this works but i want to take notEquals from a data set, any ideas?
Any one here a Kendo UI guru?
Specifically with JQuery?
20:53
21:35
I'm confused
leap seconds are a problem for big applications
Google solves it by "smearing" the seconds in the few hours around the leap second
||> const arr = new Array(4); console.log(arr); console.log(arr.every(el => el !== undefined)); console.log(arr.every(el => el === undefined)); console.dir(arr[0])
@JBis undefined Logged: [null,null,null,null], true, true
oh
its null, not undefined
21:37
@JBis undefined Logged: [null,null,null,null], true, true
@JBis undefined Logged: [null,null,null,null], true, true,
@JBis "TypeError: console.dir is not a function" Logged: [null,null,null,null], true, true
lol didn't know that google is doing that :) interesting...
||> const arr = new Array(4); arr[0]
@JBis undefined Logged: ``
there we go
Why is that undefined and not null?
||magic
21:43
(∩ ͡° ͜ʖ ͡°)⊃━☆゚. * ・ 。 ᵀᴴᴱ ᴳᴬᴹᴱ
||> const arr = new Array(4); console.log(arr); console.log(arr.every(el => el === null)); console.log(arr.every(el => el !== null));
@JBis undefined Logged: [null,null,null,null], true, true
the fuck?
@forresthopkinsa did my "speach" is correct?
are they null or undefined?
21:45
I am working right now but just post your questions and if anyone is able to help they will
oh, so you can't iterate through an empty array even if it has a length
I understood np I can wait, thanks for your interest.
CODE:
var items = [{a : 'val1', b : 'val2', c : 'val3', d : 'val4'}];

function test(array) {
  var str = 'TEST: there is NO v1, there is val2, but there is NO v3, v4 !!!';

  array.forEach(function(item) {
    if (Object.values(item).reduce(function(accumulator, currentDataValue) // [val1, val2, val3, val4]
    {
      console.log('currentDataValue: ' + currentDataValue);
      console.log('+');
      console.log('accumulator: ' + accumulator);
      console.log('==================');
      return (accumulator || str.indexOf(currentDataValue) !== -1);
(see full text)
DESCRIPTION:
forEach is run only ONCE - cause there is ONE item in an array (object). IF is run >>>ONE<<< time, cause there are 4 object properties in array item but they are 'reduced' INSIDE IF.
We did NOT put(pass) initialValue so the accumulator (previousValue) is set as the first (val1) property of the object (item inside array), and the currentDataValue is set as the second (val2) property of the object.
reduce give us >>>THREE<<< iterations for array [look at 2@2] - so return gives us back:
(see full text)
let me know if I understand this correctly.
@Proo1931 wall of text, no one is going to read
shorten your question into 1-3 sentences, then a little bit of code
|| formatting
Use a gist if its long or going to wrap
22:01
eee how I can format this? To get better readability?
use a gist
well it is description to what reduce do... and I hope it is correct. So... I can;t gist it...
every step is important... hmm copy/paste to editor will improwe it redability.
basically... break your problem down into smaller pieces
ohh, sure I can do that
we all know what reduce does and how it works
(and if we don't the docs explain it quite well)
22:10
yea I know that but the question is do I know that :)
I have read the doc and I just want to be sure...
DESCRIPTION:
forEach is run only ONCE - cause there is ONE item in an array (object).
IF is run >>>ONE<<< time, cause there are 4 object properties in array item but they are 'reduced' INSIDE IF.
We did NOT put(pass) initialValue so the accumulator (previousValue) is set as the first (val1) property of the object (item inside array),
and the currentDataValue is set as the second (val2) property of the object.
Reduce give us >>>THREE<<< iterations for array [look at 2@2] - so return gives us back:
(see full text)
are you asking us if that's how your code works?
or is there a problem somewhere in there
I hope it looks better - more redable.
eee code is working fine, I just want to be sure do I understand it correctly
oh. then set a breakpoint and step through it with a debugger
what debugger do you recommend?
hmm how do I refine a mixed type in flow to "something that supports toString()
22:23
interface with toString and make everything implement that?
but thats a pretty crappy method
Especially crappy if I have to do this for a "utility print" method.
printError(data: mixed) {
    console.log(`Data is: {data.toString()}`);
}
V.7
V.7
Hey all
https://jsfiddle.net/eu9L7x8d/
Why this one outputs an error in Console like 'Cannot read property 'document' of null'?
probably cause it can't read the property document of null ;)
|| mdn window.open
If the window couldn't be opened, the returned value is instead null.
@V.7 ^
V.7
V.7
22:59
Found
Per user one window
V.7
V.7
23:32
Thx btw
🚽
03:00 - 16:0016:00 - 00:00

« first day (3404 days earlier)      last day (1769 days later) »