Answer the question
In order to leave comments, you need to log in
What is the best way to build and solve this problem?
It is necessary to optimally implement the principle of requesting values. Here is an example:
There is a stall that sells many kinds of fruits. Each fruit (for example, an apple, a pear) has its own variety. Each variety has its own price. When the customer selects one variety of apples, we must extract the price from the array to show him. But there is a catch. We also apply a different ID to each variety. Let one variety have ID = 1023, and let the other variety have ID one thousand less, let it be 24. Thus, it may be that one pear variety has ID = 3, and an apple variety has some ID = 4, then yes ID does not specify the order of varieties and types of fruit.
So what's the best way to sort these prices? Attention, it is desirable to solve the problem without using OOP.
Option 1:
// Создаём для каждого типа свой массив
var Apples = [150,300,450]; // цены на каждый сорт
var Oranges= [220,300,450]; // цены на каждый сорт
// и т.д. все типы фруктов
// создаём общий двумерный массив
var Array = [
[1000,250], // первое значение есть ID сорта (это может быть и яблоко, и груша и что угодно), второе - цена сорта
[1032,300], // ..
[2034,270] // ..
// ...
];
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question