13eck
13eck
Explore posts from servers
KPCKevin Powell - Community
Created by عبد الحي on 6/25/2024 in #front-end
array doesn't want to go away
Nah. We’ll tag-team a codebase instead :p
22 replies
KPCKevin Powell - Community
Created by عبد الحي on 6/25/2024 in #front-end
array doesn't want to go away
That works, too, yeah. I like the ternary operator, what can I say? 😉
22 replies
KPCKevin Powell - Community
Created by عبد الحي on 6/25/2024 in #front-end
array doesn't want to go away
Sure thing! Hope it helps
22 replies
KPCKevin Powell - Community
Created by عبد الحي on 6/25/2024 in #front-end
array doesn't want to go away
The reduce() function's first parameter is a function that has two parameter: the accumulator (which is the current value passed in from all prior loops) and the value (which is the current value at the index being looped over). You then pass an empty array as the initialValue so you have a new, empty, array to work with. On each loop, you want to check if the value is a string, if it is you add it to the accumulator. If not, you do nothing. Be sure to return the accumulator in the callback function so it can be used in the next loop.
22 replies
KPCKevin Powell - Community
Created by عبد الحي on 6/25/2024 in #front-end
array doesn't want to go away
Both .map() and .filter() can be done using .reduce()
22 replies
KPCKevin Powell - Community
Created by عبد الحي on 6/25/2024 in #front-end
array doesn't want to go away
.reduce()? Yes
22 replies
KPCKevin Powell - Community
Created by عبد الحي on 6/25/2024 in #front-end
array doesn't want to go away
Not with .map(), no
22 replies
KPCKevin Powell - Community
Created by عبد الحي on 6/25/2024 in #front-end
array doesn't want to go away
.map() won't change the array length, though. It'll always return an array of 11 items (as your initial array has that many items)
22 replies
KPCKevin Powell - Community
Created by عبد الحي on 6/25/2024 in #front-end
array doesn't want to go away
It's because you're using the .map() function, which takes in an array of X items and returns an array of the same number of items. Also, you're creating a new array in each loop for no reason—just return el instead. What you should be using is the .filter() function, which takes in an array of X items and returns an array of that many or less.
const newMix = mix.filter( x => {
if (typeof(x) == "string") return true;
else return false;
});
const newMix = mix.filter( x => {
if (typeof(x) == "string") return true;
else return false;
});
Which can be made even more succient by:
const newMix = mix.filter( x => (typeof(x) == "string") ? true: false);
const newMix = mix.filter( x => (typeof(x) == "string") ? true: false);
Lastly, please use code blocks (putting code between ``` ) so we can copy/paste your code. Going off of a screenshot isn't very helpful.
22 replies
KPCKevin Powell - Community
Created by Eighth on 5/16/2024 in #front-end
Bitwise operations
What have you tried so far?
7 replies
KPCKevin Powell - Community
Created by Light on 5/14/2024 in #ui-ux
Food/Coffee Truck Website with Location/Calendar (Feedback would be lovely!)
That’s pretty boss!
10 replies
KPCKevin Powell - Community
Created by Stroudy on 5/4/2024 in #front-end
JavaScript cheat sheet
As this is not about a specific bit of code you should re-post over in #discussions. This channel is for getting help with specific bits of code.
2 replies
KPCKevin Powell - Community
Created by cat on 4/26/2024 in #front-end
creating calculator
They're typing. Be patient 😉
161 replies
KPCKevin Powell - Community
Created by cat on 4/26/2024 in #front-end
creating calculator
☝️ @ἔρως
161 replies
KPCKevin Powell - Community
Created by cat on 4/26/2024 in #front-end
creating calculator
I'd suggest using a switch statement to handle the operation of currentOperator
161 replies
KPCKevin Powell - Community
Created by cat on 4/26/2024 in #front-end
creating calculator
So you have a global object that stores what's being used. The first function there changes the opeartor to +, -, /, or * as necessary (based on the button pressed) and the array holds the numbers that need be operated on. So if you type 15 + 4 the 15 is pushed into the array, the + is added as the operator and then 4 is pused to the array. You'll want to add more functionality to actually do the operation on each operatorButtonClicked—so the next time you click on, say, - it'll add 15 and 4, clear the array, and add 19 to the array
161 replies
KPCKevin Powell - Community
Created by cat on 4/26/2024 in #front-end
creating calculator
something like:
let state = {
currentOperator: undefined,
numbersToOperateOn: []
}

const operatorButtonClicked = (ev) => {
state.currentOperator = ev.target.data.operation
}

const numberButtonClicked = (button) => {
numbersToOperateOn.push(button.valueAsNumber)
}
let state = {
currentOperator: undefined,
numbersToOperateOn: []
}

const operatorButtonClicked = (ev) => {
state.currentOperator = ev.target.data.operation
}

const numberButtonClicked = (button) => {
numbersToOperateOn.push(button.valueAsNumber)
}
161 replies
KPCKevin Powell - Community
Created by cat on 4/26/2024 in #front-end
creating calculator
You should be saving state in JS, not via HTML/CSS
161 replies
KPCKevin Powell - Community
Created by cat on 4/26/2024 in #front-end
creating calculator
If you're trying to use that to see what operation to use don't use bg colour. Save the button press in a variable and read that
161 replies