'Visual Studio Code Class Selection for multiple identical names

So I can across this today and it might already have been answered somewhere but I'm curious why this isn't picking up all classes with the same name. So I have two requires from two different classes of two different areas of testing that have the same name.

Const AreaOneLoginPage = require('../../pages/areaOne/login.page');
Const areaOneLoginIn = new AreaOneLoginPage();
Const AreaTwoLoginPage = require('../../pages/areaTwo/login.page');
Const areaTwoLoginIn = new AreaTwoLoginPage ();

However when I try to construct this in a different way using the smart logic in Visual Studio Code. This always defaults to AreaOne.

Const areaOneLogin = new LoginPage(); //<== This is the class name of the first area.
Const areaTwoLogin = new LoginPage(); //<== This is the class name of the second area.

The only option Visual Studio picks up is AreaOne and not show all the Classes that link into LoginPage??

Is this just a Visual Studio thing that can be fixed or is this a javascript thing?

Or is it best to refactor the class names to two different names completely. I just figured that VS Code would be able to determine that the class is nested below a seperate folder location?



Solution 1:[1]

You can import the one module in one file many times, if they will be named unique. And then you can create new objects from these classes/modules.

To prevent this we have Singleton Pattern. it saves the instance of itself and if there was the init earlier, you will get the instance of exsisting object instead of creating new one.

Hope this was the answer to your question

Solution 2:[2]

Although your input is 10 20 30 40 50 which would make you believe that those are integers (int), Python's input returns a str. Thus transforming your input into integers will make your code work as you seem to expect.

array = [int(n) for n in input().split()]
print(array) # Out[0]: [10, 20, 30, 40, 50]
...

Solution 3:[3]

array = []
array = input().split()

array = [int(x) for x in array]

for i in range(len(array)):
    max_index = i
    for j in range(i + 1, len(array)):
        if int(array[j]) > int(array[max_index]):
            max_index = j
    array[i], array[max_index] = array[max_index], array[i]

    print(array)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mykola MASTEMA
Solution 2 Felipe Whitaker
Solution 3