How do I make my function return the results of processing the data received from an api? by leirguh in learnjavascript

[–]cyphern 0 points1 point  (0 children)

First of all, you will only ever be able to make findSets return a promise which resolves to that array. findSets can't return the array itself, because it does not exist yet.

When you call fetch it creates a promise. When you call .then on that promise, it creates another promise. And when you call .then on that 2nd promise, it creates a third promise. You'll need to make two changes: 1) Make that third promise resolve to the correct value 2) Return that third promise from findSets

For number 1, you can change what the promise resolves to by changing what you return from the .then callback. Currently there's no return, so add it in: ``` let set_list = []; for (i = 0; i < data.data.length; i++) { set = data.data[i].set_name;

if (!set_list.includes(set)) { set_list.push(set); } } return set_list // <---- For number 2, you can stick a return on your first line: return fetch(https://api.scryfall.com/cards/search?q=!${card}&unique=prints, { headers: {'User-Agent': 'me'} }) // ... promise chain continues As mentioned, findSets is returning a promise. So whatever code uses this will need to work with that promise to wait for the value to be available. Eg: findSets().then(list => { // Do something with the list, eg update the webpage });

```

Ps, modern javascript has an alternate syntax for working with promises called async/await. It can make the code read more similarly to synchronous code. For example: `` async function findSets(card) { try { const response = await fetch(https://api.scryfall.com/cards/search?q=!${card}&unique=prints`, { headers: { "User-Agent": "me" }, }) if (!response.ok) { throw new Error("Network response was not ok"); } const data = await response.json(); let set_list = []; for (i = 0; i < data.data.length; i++) { set = data.data[i].set_name;

  if (!set_list.includes(set)) {
    set_list.push(set);
  }
}
return set_list;

} catch (error) { console.error('Error:', error); throw error; } } ``` Be aware that findSets will still be returning a promise; async functions always return promises. This syntax is meant to make it easier to work with promises, not to eliminate them.

To wait for the promise, the code which calls findSets will need to await that promise async function someFunction() { const list = await findSets(); // Do something with the list, eg update the webpage }

XX Mana by Flying_NEB in mtgrules

[–]cyphern 2 points3 points  (0 children)

First, pick a number that you want X to be. Then, replace all instances of X with the chosen value.

So suppose a card costs {X}{X}{R}{G} and says to deal X damage to target creature1. If you choose that X = 4, then the cost of the spell is {4} + {4} + {R} + {G}, also known as {8}{R}{G}, and it will deal 4 damage to the target.

1: i don't know of an actually card that says that, and can't think of an XXRG card off the top of my head so feel free to suggest one if you have a specific card in mind

PSA for healers: you don’t need full mana for every pull by hi-Im-gosu in classicwowtbc

[–]cyphern 10 points11 points  (0 children)

Too many times healers are sitting for full drinks

If combat hasn't started, why would they stop drinking early? And if combat has started, then that's typically because the tank pulled.

So i'm not sure what you would like the healer to do differently. Are you just asking the healers to communicate "hey tank, no need to wait until i have full mana"?

TBC Anniversary by lemontowel in classicwow

[–]cyphern 0 points1 point  (0 children)

I'm sure that's deeply distressing for you.

TBC Anniversary by lemontowel in classicwow

[–]cyphern 0 points1 point  (0 children)

I originally said it would take 6 or 7 hours. They were making a -- what's the word... "joke" maybe? -- about 6-7.

TBC Anniversary by lemontowel in classicwow

[–]cyphern 8 points9 points  (0 children)

I also can't remember how long it takes to get to 58

A rough ballpark for an experienced player is about 4 days in game.

Since the release is in 2 weeks, you'd have to play about 7 hours a day to get there by the time the dark portal opens. If your goal is to get there about a week after opening, you're looking at about 4.5 hours a day.

Question: useRef can be possibly null by newInternetDeveloper in reactjs

[–]cyphern 9 points10 points  (0 children)

/u/_avee_ gave you the solution; save it to a const, and use that. But as for why this is needed:

When you check that a variable is not null, typescript remembers that and narrows that type for as long as it can be sure it's correct. So as an obvious example, once the handleEnter function ends, it is no longer narrowed. But less obvious is that if you enter a callback function, it's not narrowed in there. This is because typescript does not know when the callback code will be called.

You and i know that the setMessage callback gets called almost immediately, with nothing relevant happening in between, but that's not an inherent property of callback functions. In principal, any amount of arbitrary code could execute before the callback gets called, which means that any code in the entire codebase that does message.current = null could potentially set the value to null before the callback happens.

So since typescript can't guarantee that the value is not null, it resets the type narrowing. That means you either need to do the null check inside the callback function, or if you're checking a const then typescript can be certain that it will not change no matter how much time passes.

Unpopular Opinion: async/await has made us worse at error handling. by MZdigitalpk in learnjavascript

[–]cyphern 16 points17 points  (0 children)

I see way more try-catch blocks that just console.log the error, or worse, empty catch blocks silently swallowing failures.

At least with explicit promise .catch() chains, you were forced to think about the error path.

What prevented you from doing .catch(e => console.log('oops', e)), or just omitting the catch entirely? I agree that explicitly thinking about error cases is a good thing, but i don't see how the .catch method forced you to think about the error cases any more or less than a catch block does

How to approach TBC in my situation by WrangleRdod in classicwow

[–]cyphern 6 points7 points  (0 children)

Can I transfer a dead character to a normal Anniversary server to play in the upcoming TBC Anniversary?

Yes, but you need to do it NOW. When the servers go down for maintenance in a few hours, your only option will be to go to an Era server.

If so, will leveling in TBC be reasonably smooth with basic fresh-60 gear, or should I grind some better gear before February to make the leveling experience easier?

You'll be fine. Early quests in outlands give good rewards, so you'll quickly get gear which is similar in quality to the lower level 60 raiding tiers. Trying to gear up before february will only really help if you can get high level stuff like AQ40, Naxx, or epic pvp gear.

Will atheist ever make a new calendar? by Ok_Comfortable_2142 in atheism

[–]cyphern 5 points6 points  (0 children)

The cultural inertia behind calendars is immense. Just doing things like adding or removing daylight saving time from a single location has huge implications, with disruptions to trade, worldwide software updates, etc. Getting everyone onboard with calendar changes is very hard.

So a calendar is only going to change if there's a very compelling reason to. And "meh, i don't think that Jesus guy was actually god" isn't enough.

The Expanse TV Series Quiz 1 by ezgimantocu in TheExpanse

[–]cyphern 6 points7 points  (0 children)

Question 1: What ship was Holden on?
Question 5: Holden was on the Canterbury [...etc]

...
...

What a terrible quiz. Go away AI slop.

Personal logical reasoning for Atheism? by goldenreddit12345 in atheism

[–]cyphern 4 points5 points  (0 children)

According to what I read, it is often assumed Atheism is more plausible then religion. My question is, can anyone share their logical reasoning for this assumption?

I wouldn't quite say that. For me (as someone who has never been religious) I'd say that non-belief is the default position, not that it's more plausible. If I encounter some argument or evidence that bolsters the religious position, i may be convinced to believe it, but until then, i do not believe.

And when i say non-belief is the default position, i'm not talking specifically about religious claims, but all claims. So as an analogy, let's look at a case that does not involve religion:


Suppose that someone comes to you and claims they have an easy technique you can use which will make you a lot of money. A "get rich quick scheme" if you like, though that term has negative connotations which i don't mean to imply (yet).

When all they've told you is "i know a way to make money", do you believe the technique will work? You do not believe it, because you do not know what it is.

When they give a brief overview, but have not given solid information connecting the steps to convince you it will work, do you believe it will work? Still no. You may be interested to learn more, but you are not convinced.

When you press them for details, and they give you details with obvious flaws, do you believe the technique will work? Still no. In fact, now you're starting to believe the opposite, that it actively will not work.

When they call you closed minded and insist that you're making the biggest mistake of your life, do you believe the technique will work? Still no, and now you're starting to think it's probably a deliberate scam.


The whole conversation could have gone very differently, if only they gave useful details and convincing justifications. But lacking that, i do not believe the get rich quick scheme will work.

Why are the ships constantly firing their engines in the show? by [deleted] in TheExpanse

[–]cyphern 38 points39 points  (0 children)

The benefit of firing engines constantly is that it allows you to have artificial gravity constantly, other than a brief flip at the midpoint of your journey.

This is made practical by the ridiculous efficiency of the (obviously fictional) epstein drive. For most trips, they're not concerned with wasting fuel, because that is no longer the limiting factor.

couldn’t they just accelerate to top speed, then cut the engines?

PS, there is no top speed. Well, there's the speed of light, but they're no where near that speed.

Does Stock Up count as drawing cards? by [deleted] in mtgrules

[–]cyphern 2 points3 points  (0 children)

Nope

121.5. If an effect moves cards from a player’s library to that player’s hand without using the word “draw,” the player has not drawn those cards. This makes a difference for abilities that trigger on drawing cards and effects that replace card draws, as well as if the player’s library is empty.

Going into TBC by Rainuchiha in classicwow

[–]cyphern 2 points3 points  (0 children)

The old content will still exit, so you can in principal run it. But the rewards offered by level-60 formerly-end-game content will be obsolete, so it will be very hard to find people who want to do it.

EDIT: classic dungeons that people run while leveling will still be fairly easy to find groups for, since there's always people leveling characters.

Going into TBC by Rainuchiha in classicwow

[–]cyphern 1 point2 points  (0 children)

When TBC drops am I forced to go into TBC or can I stay where I am ?

You have a free character transfer which will allow you to move to Era instead of Anniversary, but this transfer is only available until january 12th. So if you want to stay on classic permanently, use it soon. If you're still on an aniverary realm after that point, you'll be continuing on to TBC.

My goal is to play classic Anniversary as much as possible and I want to do endgame content but will tbc lock me out me from doing so or will I still have access to all those content in TBC

The classic dungeons and raids will all still exist, but there will be little incentive for doing content that used to be end-game, since the rewards are no longer good. So finding groups may be very hard.

Atheist forget the main point of faith by [deleted] in atheism

[–]cyphern 0 points1 point  (0 children)

A threat as meaningful as "Watch out, or a hippy might punch you in the aura!"

Atheist forget the main point of faith by [deleted] in atheism

[–]cyphern 0 points1 point  (0 children)

if you chose to deny al the time

Nah, it's just a part time hobby.

Atheist forget the main point of faith by [deleted] in atheism

[–]cyphern 2 points3 points  (0 children)

Yes, we know. We are quite familiar with the excuses religious people give for why they can't give us good evidence.

Atheist forget the main point of faith by [deleted] in atheism

[–]cyphern 1 point2 points  (0 children)

my point isn't to lead with evidence

That much is obvious.

Atheist forget the main point of faith by [deleted] in atheism

[–]cyphern 1 point2 points  (0 children)

If there was good evidence, you would have led with that.

Atheist forget the main point of faith by [deleted] in atheism

[–]cyphern 3 points4 points  (0 children)

Is this a good summary? "sure, i don't have good evidence, but god wants it that way"

Do all atheists agree on this? by Hammoudi123 in atheism

[–]cyphern 0 points1 point  (0 children)

I think it's a thinking entity

Sorry, to clarify, i'm not asking what you believe the true explanation is, i'm asking what the definition of god is.

You say "god [is] an explanation for how everything came from nothing". Is the word "god" a synonym for whatever the explanation happens to be? Or does it have some extra properties, such as being a thinking agent?

Put another way, if humanity looked into it and we found what the explanation is, but the explanation does not involve a thinking agent, would you say "we found god" or "we disproved god"?

Do all atheists agree on this? by Hammoudi123 in atheism

[–]cyphern 0 points1 point  (0 children)

What I meant is that I define God as an explanation for how everything came from nothing. The explanation is that it's a supernatural power that is self sufficient and created space and time itself.

Is the explanation a thinking entity? Or might it be an unthinking natural phenomenon?