Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use one array for all data. #9

Closed
MHenderson opened this issue Aug 24, 2023 · 3 comments
Closed

Use one array for all data. #9

MHenderson opened this issue Aug 24, 2023 · 3 comments
Assignees

Comments

@MHenderson
Copy link
Owner

MHenderson commented Aug 24, 2023

[{value: 1, korean: "하나", sino: "일"}, ...]

I think the find method is all I need to query such an array depending on the game mode.

https://www.w3schools.com/jsref/jsref_find.asp

@MHenderson
Copy link
Owner Author

const numbersArray = [
  { value: 1, korean: "하나", sino: "일" },
  { value: 2, korean: "둘", sino: "이" },
  { value: 3, korean: "셋", sino: "삼" },
  { value: 4, korean: "넷", sino: "사" },
  { value: 5, korean: "다섯", sino: "오" },
  { value: 6, korean: "여섯", sino: "육" },
  { value: 7, korean: "일곱", sino: "칠" },
  { value: 8, korean: "여덟", sino: "팔" },
  { value: 9, korean: "아홉", sino: "구" },
  { value: 10, korean: "열", sino: "십" }
];

x = numbersArray.find((x)=>x.value==6);

// Log to console
console.log(x.korean)
console.log(x.sino)

@MHenderson MHenderson self-assigned this Aug 24, 2023
@MHenderson
Copy link
Owner Author

This might be preferable:

const result = numbersArray.find(({ value }) => value === 5);

console.log(result.korean)
console.log(result.sino)

@MHenderson
Copy link
Owner Author

An alternative might be to initialise a new Question/Answer array, depending on mode

// korean to number game
exercises = numbersArray.map(d => ({ question: d.korean, answer: d.value}) )

// sino-korean to number game
exercises = numbersArray.map(d => ({ question: d.sino, answer: d.value}) )

// number to korean guessing
exercises = numbersArray.map(d => ({ question: d.value, answer: d.korean}) )

// number to sino-korean guessing
exercises = numbersArray.map(d => ({ question: d.value, answer: d.sino}) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant