These are chat archives for FreeCodeCamp/Help

27th
Jan 2019
baiselog
@baiselog
Jan 27 05:58
hello
what are you弄啥咧
tundeiness
@tundeiness
Jan 27 13:04
Hi guys!. So I am attempting the drum-machine project here and I have been thinking and making research on how to approach it. Now I am getting conflicting feed backs with using AddEventListeners in React. some advise that using Event is best as event listeners are in built into react, while some are suggesting it usage. What advice do you guys have? Another thing is the state. should I still go ahead with using react to handle the state or this is the time to involve Redux? I am asking because of the number of sounds to fetch from a server and played simultaneously when the key to that sound is pressed. Looking forward to your advise.
May Kittens Devour Your Soul
@diomed
Jan 27 13:51
Amadeo Idomeneo
May Kittens Devour Your Soul
@diomed
Jan 27 15:46
@Nirajn2311 when shall we play hangman again?
Aditya
@ezioda004
Jan 27 16:48
@tundeiness Using event listeners on window, document object is fine in React.
As far as state is concerned for this app - I only used local state as my components were only passing state 1 level deep
psyperl
@psyperl
Jan 27 17:28
@diomed no more people hanging plox
Levis
@agabyte
Jan 27 18:19
Hi, I'm trying to make a copy of a const array so I can sort it but having difficulties.
var code='formatted';
const arr = [5,4,3,2,1]; 
//before sorting
console.log(arr);
const copy1 = arr.slice();
var copy2 = arr.slice();

copy1.sort();
copy2.sort();
console.log(copy1);
console.log(copy2);

arr.sort();
//after sorting
console.log(arr)
Levis
@agabyte
Jan 27 18:26
why wont sort work on this array? var a = [12,31,22,17,25,18,29,14,9]
Christopher McCormack
@cmccormack
Jan 27 18:30
@agabyte sort, by default, treats each element as a string and sorts in lexicographical order. You will need to use the callback parameter of sort to define a custom sort function to apply against each element
arr.sort(function(firstElement, secondElement) {/* custom sort logic */})
Levis
@agabyte
Jan 27 18:31
thanks @cmccormack
psyperl
@psyperl
Jan 27 18:32
9 comes after 14 because 9 is larger than 1
Levis
@agabyte
Jan 27 18:32
yeah
a.sort((a,b)=>{a-b})
Christopher McCormack
@cmccormack
Jan 27 18:32
:thumbsup:
that won't work until you remove the curly braces though
or add a return
Arrow function implicitly returns the value after the arrow, adding block means, unless you explicitly add a return, undefined will be returned (I believe)
psyperl
@psyperl
Jan 27 18:34
would be nice if the argument of anon function is set implicitly as a predefine variable ... a.sort( => $0 - $1 ) .. i will vote for this feature for future JS version
Christopher McCormack
@cmccormack
Jan 27 18:37
but $# might already be used by someone in their code, that could possibly break it
but I like it
psyperl
@psyperl
Jan 27 18:38
£ or maybe? lol
but yeah any symbol is fine
Christopher McCormack
@cmccormack
Jan 27 18:42
hah good luck convincing US to use symbols not already on the keyboard explicitly
psyperl
@psyperl
Jan 27 18:42
lol
tundeiness
@tundeiness
Jan 27 20:31
@ezioda004 no redux for me then...but I have two functionalities i am adding to this project: the play and record button. The record button when clicked will aim to listen out for the sound pressed by the user and then store it in an array. So when the play button is clicked, it stops the recording mode and in turn plays the sounds selected by the user at the time of recording by looping over the array . what do you advice?
Niraj Nandish
@Nirajn2311
Jan 27 21:21
@diomed soon, my apprentice
soon