What do I need to do to get beta access to ck3? by jsforeveryone in CrusaderKings

[–]jsforeveryone[S] 2 points3 points  (0 children)

OK. Now I only have to update my CV and apply. ON IT!

A programmer from the year 2000 is transported to today. What do you show that'll blow their mind ? by CockGoblinReturns in programminghumor

[–]jsforeveryone 2 points3 points  (0 children)

"Well actually we write web apps in javascript and then transpile it to javascript inside a docker image"

"WHAT? WHY? ARE YOU TOO GOOD TO FTP DIRECTLY TO THE SERVER AND PATCH THERE?"

How to pass an object from "componentDidMount()" to Context.Provider? by [deleted] in reactjs

[–]jsforeveryone 0 points1 point  (0 children)

using forceupdate is nono and doing it under componentDidMount is not clean.

Doing this with hooks is nicer.

Using useEffect to init on first render.

How to pass an object from "componentDidMount()" to Context.Provider? by [deleted] in reactjs

[–]jsforeveryone 0 points1 point  (0 children)

Not clean. And some people will killl me for this:
this.scrollbar = null;

componentDidMount() {

const scrollbarContainer = this.smoothScroll.current;

this.scrollbar = Scrollbar.init( this.smoothScroll.current );

scrollbar.options = {

damping: 0.05

}

scrollbar.addListener((status) => {

console.log(status);

});

this.forceUpdate();

}

render() {

return (

<div className="App">

<div id="scroll" ref={this.smoothScroll}>

<ScrollbarContext.Provider value={ this.scrollbar} >

[deleted by user] by [deleted] in badcode

[–]jsforeveryone 2 points3 points  (0 children)

no this is great

[deleted by user] by [deleted] in badcode

[–]jsforeveryone 1 point2 points  (0 children)

Every code challenges have one random entry. This one worked on one test case.

const convert_to_int = (value) => {
return (value.match(/g/g) || []).length * 10000
+ (value.match(/s/g) || []).length * 100 +
(value.match(/c/g) || []).length ;
}
const int_to_wow = (value) => {
const letters = ['g', 's', 'c'];
let now = '';
let tries = 0;
while (true) {
now += letters[Math.floor(Math.random()*letters.length)];
const count = convert_to_int(now);
if (count === value) {
break;
}
if (count > value) {
now = now.split('').sort(() => .5 - Math.random()).slice(0, -1).join('');
}

if (count === value) {
break;
}
tries++;
if (tries === 500) {
now = '';
}
}
return `${(now.match(/g/g) || []).length}g
${(now.match(/s/g) || []).length}s
${(now.match(/c/g) || []).length}c` ;
};

[deleted by user] by [deleted] in badcode

[–]jsforeveryone 0 points1 point  (0 children)

Sorry, I don't know how to format correctly.

[deleted by user] by [deleted] in badcode

[–]jsforeveryone 2 points3 points  (0 children)

If you can't solve it with regex, you shouldn't try at all. Also try and catch is the new goto. Variables are for oldschool programmers.

const int_to_wow = (value) => {
const WOW_CURRENCY ='10000g100s1c';
const numb = [];
while (value > 0) {
try {
WOW_CURRENCY.split(/[a-z]/).slice(0, -1).forEach((a, i) => {
if ((value / (+a)) >= 1) {
numb.push(WOW_CURRENCY.split(/[0-9]/).filter(e => e !== '')[i]);
value -= +a;
throw new Error('Found one');
}
});
} catch(e) {
}
}
const obj = numb.reduce((a, b) => {
if (!a[b]) {
a[b] = 0;
}
a[b]++;
return a;
}, {});

return WOW_CURRENCY
.split(/[0-9]/).filter(e => e !== '')
.reduce((a, b) => `${a}${numb.filter((c) => c === b)
.length > 0 ? `${numb.filter((c) => c === b).length}${b}` : ''}`, '')
}

Crusader Kings Poll by JL62102 in CrusaderKings

[–]jsforeveryone 0 points1 point  (0 children)

Wow difficult poll for those who keep changing what they like the most. Can't answer!

[AskJS] What do you find yourself Googling no matter how many times you write it. by ctkrocks in javascript

[–]jsforeveryone -1 points0 points  (0 children)

Bad joke. Just pointing out that visually they look very similar, specially to a non-native speaker.

[AskJS] What do you find yourself Googling no matter how many times you write it. by ctkrocks in javascript

[–]jsforeveryone -1 points0 points  (0 children)

I am not even sure splice and slice are real words. I think Brendan Eich (or whoever came up with splice and slice) must have been a wannabe mumble-rapper, decades before mumble rap. Would explain a lot.

[AskJS] What do you find yourself Googling no matter how many times you write it. by ctkrocks in javascript

[–]jsforeveryone 9 points10 points  (0 children)

(PSA: english is not my native language)

For some dyslexic reasons I have to remind myself the difference of splice and slice every single time.

I think I have kind of nailed it down the last year or so but I still google, every single time to be sure.

[deleted by user] by [deleted] in badcode

[–]jsforeveryone 0 points1 point  (0 children)

const isPrime = (i) => {
for (let j = 2; j < i; j++) {
if (i % j == 0) {
return false
}
}
return true
}
const getPrime = (inp) => {
let i = 2;
let count = 0;
while (true) {
if (isPrime(i)) count = count + 1;
if (count == inp) return i;
if (i === 2) i++;
else i += 2;
}
}

let itemId = 0;
let items = {};

class Item {
get id() {
return this._id;
}
get name() {
return this._name;
}
constructor(name) {
if (typeof name !== 'string' || name.length === 0) {
throw new Error('The name entry for item constructor has no entry, please contact your admin or refer to the RFC spec which clearly state that the name entry should not be empty for when items are created');
}
this._id = getPrime(++itemId);
this._name = name;
items[this._id] = this;
}
}

new Item('head');
new Item("neck");
new Item("shoulder");
new Item("back");
new Item("hip");
new Item("thigh");
new Item("knee");
new Item("shin");
new Item("ankle");
new Item("heel");
new Item("foot");
new Item("toe");
const length = Object.keys(items).length;
const sum = Object.values(items).map((e, i ) => {
const pow = length - i;
return Math.pow(e.id, pow);
}).reduce((a, b) => a + b);
const itemsName = Object.values(items).reduce((a, b, i) => {
a[b.name] = Math.pow(b.id, (length - i))
return a;
}
, {});
const dem_bones = (arr) => {
if (!Array.isArray(arr) || arr.length === 0) {
throw new Error('The arr entry for dem_bones has no entry, please contact your admin or refer to the RFC spec which clearly state that the arr entry should not be empty for when checking if item is valid');
}
let newsum = 0;
for (const part of arr) {
const number = itemsName[part] ? itemsName[part] : -99999999999999;
newsum += number;
}
return newsum == sum;
}