ux field – Understanding the problem statement

I have given the following problem statement to come up with a solution. The solution must be a short format communication platform meant for workplaces (TikTok/Instagram Stories). However, I struggle to understand the approach. I have been doing a competitor analysis but couldn’t find any similar competitors. Appreciate it if any of you can provide ideas or a couple of low fidelity ideas to get started.

enter image description here

javascript – Count looped results in if statement and display results

I am trying to figure out how to count results based on the looped data and if statements.

My javascript below, will loop through response(j).resortcode and add a div for every response(j).roomcode within a div matching that resortcode. What I would like to do is make use of the if statement.

I would like to count like so:
If there are no roomcodes within that resortcode that available => 1, output Sold Out
If there are any roomcodes wiithin that resortcode that available => 1, output the count for only those results.

If SSR has 9 rooms, but only 4 show as available. My count would be 4.
If SSR has 9 rooms, and all available = 0. It would just output sold out.

My count output would go to the premade header via id.

The current coding is already working correctly. I just want to add to it. I am confused on where to start with this, assuming after my if statements or possibly create an outside function and tie it in? I am open to anything, help, advice, etc.

let searchresult = function(response) {

    
    let resortCodes = new Set();
    for (let j = 0; j < response.length; j++) {

        resortCodes.add(response(j).resortcode);
        let divID = 'results-' + response(j).resortcode;
        let container = document.getElementById(divID);
        let price = response(j).points.toString().replace(/B(?=(d{3})+(?!d))/g, ",");

              if (response(j).available < 1) {
                var available = 'soldoutresult"';
                var btn = '<button type="button" class="soldout">SOLD OUT</button>';
              }
              else {
                var available = 'availableresult"';
                var btn = '<button type="button" class="booknow">BOOK NOW</button>';
              }


        container.innerHTML += `
            <div class="roomresults ${available}">

            <div class="roomthumb"">
              <center><button class="myBtn roomdetailsbtn" data- 
                target="#modal${response(j).roomcode}" data-toggle="modal">Room 
                Details</button>
              </center>
            </div>

            <div class="roominfo"><p class="roomtitle">${response(j).roomname} - 
                ${response(j).viewname}</p>
            </div>
            </div>
            `
          }
        };
    <div id="akvjhcontainer" class="resortcontainer">
        <div id="akvjhheader" class="resortheader">
            <div class="headertext"><p class="resortnametext">Animal Kingdom Villas - Jambo House</p><p class="locationtext">Walt Disney World - Orlando, Florida</p></div>
            <div id="count-akvjh" class="collapseBTN"> COUNT RESULTS HERE <button class="collstyle" data-toggle="collapse" data-target="#results-AKV"><i></i></button></div>
        </div>
        <div id="results-AKV" class="results-AKV collapse show"></div>
    </div>

    <div id="akvkvcontainer" class="resortcontainer">
        <div id="akvkvheader" class="resortheader">
            <div class="headertext"><p class="resortnametext">Animal Kingdom Villas - Kidani Village</p><p class="locationtext">Walt Disney World - Orlando, Florida</p></div>
            <div id="count-AKV2" class="collapseBTN"> COUNT RESULTS HERE <button class="collstyle" data-toggle="collapse" data-target="#results-AKV2"><i></i></button></div>
        </div>
        <div id="results-AKV2" class="results-AKV2 collapse show"></div>
    </div>

    <div id="aulcontainer" class="resortcontainer">
        <div id="aulheader" class="resortheader">
            <div class="headertext"><p class="resortnametext">Aulani</p><p class="locationtext">Kapolei, Hawaii</p></div>
            <div id="count-AULV" class="collapseBTN"> COUNT RESULTS HERE <button class="collstyle" data-toggle="collapse" data-target="#results-AULV"><i></i></button></div>
        </div>
        <div id="results-AULV" class="results-AULV collapse show"></div>
    </div>

Thanks in advance. I always appreciate those willing to help.

clean code – How does this switch statement do “multiple things”?

Martin’s concept of “do one thing” is overly ambiguous to the point I believe it does more harm than good.

In the passage Martin states that a switch does one thing per case and therefore by definition does N things. This implies that any single method call is “one thing”. If you follow this thinking, you will quickly realize a program will never be able to do anything!

Martin has a different definition which is that a method does “one thing” when all operations are on the same abstraction level. But the cases here calculateCommissionedPay(), calculateHourlyPay() do seem to be on the same abstraction level, so this contradicts his general criticism of switch-statments as always doing N-things.

That said, there are reasons to avoid this particular use of a switch. The switch check a type-field and then selects the method to call based on that. The idiomatic way to do this in object oriented programming is to use subclasses and overloading. Employee could have subclasses HourlyEmployee, SalariedEmployee etc., which override a calculatePay() method. That way you could avoid the switch altogether and just call e.calculatePay().

But if the input really is an enum value as in the example, then you need a way to get the appropriate Employee-subclass given this enum value. How do you do that? A switch of course! So you end up with code something like this:

public Employee createEmployee(int employeeType)
throws InvalidEmployeeType {
    switch (employeeType) {
      case COMMISSIONED:
        return new CommissionEmployee(e);
      case HOURLY:
        return new HourlyEmployee(e);
      case SALARIED:
        return new SalariedEmployee(e);
      default: 
        throw new InvalidEmployeeType(e.type);
    }
}

public Money calculatePay(int employeeType)
throws InvalidEmployeeType {
    Employee e = createEmployee(e.type);
    return e.calculatePay();
}

You will notice a few things:

  1. We still have a switch which allegedly does “N-things”.
  2. The switch will still have to grow when new employment types are added.
  3. We still have a Open/Closed violation, since adding a new subclass will require us to modify the switch, just as before.

But if there are multiple places in the code were we switch on the employee type as in the first example, this refactoring is a clear improvement since we now only need one single switch and can use overloading in the other places.

Graph Theory statement proof

I can’t figure out how can I solve this problem

Let b1, b2, . . . , bk be positive integers with sum less than n. Prove that then b1!b2! . . . bk! < n!
holds.

postgresql – Why is OR statement slower than UNION

Database version: Postgresql 12.6

I have a table with 600000 records.

The table has columns:

  • name (varchar)
  • location_type (int) enum values: (1,2,3)
  • ancestry (varchar)

Indexes:

The ancestry column is a way to build a tree where every row has an ancestry containing all parent ids separated by ‘/’

Consider the following example:

id name ancestry
1 root null
5 node ‘1’
12 node ‘1/5’
22 leaf ‘1/5/12’

The following query takes 686 ms to execute:

SELECT * FROM geolocations
WHERE EXISTS (
   SELECT 1 FROM geolocations g2
   WHERE g2.ancestry = 
      CONCAT(geolocations.ancestry, '/', geolocations.id)
)

This query runs in 808 ms seconds:

SELECT * FROM geolocations
WHERE location_type = 2

When combining both queried with an OR it takes around 4 seconds 475 ms to finish if it ever finishes.

SELECT * FROM geolocations
WHERE EXISTS (
   SELECT 1 FROM geolocations g2
   WHERE g2.ancestry = 
      CONCAT(geolocations.ancestry, '/', geolocations.id)
) OR location_type = 2

Explain:

(
  {
    "Plan": {
      "Node Type": "Seq Scan",
      "Parallel Aware": false,
      "Relation Name": "geolocations",
      "Alias": "geolocations",
      "Startup Cost": 0,
      "Total Cost": 2760473.54,
      "Plan Rows": 582910,
      "Plan Width": 68,
      "Filter": "((SubPlan 1) OR (location_type = 2))",
      "Plans": (
        {
          "Node Type": "Index Only Scan",
          "Parent Relationship": "SubPlan",
          "Subplan Name": "SubPlan 1",
          "Parallel Aware": false,
          "Scan Direction": "Forward",
          "Index Name": "index_geolocations_on_ancestry",
          "Relation Name": "geolocations",
          "Alias": "g2",
          "Startup Cost": 0.43,
          "Total Cost": 124.91,
          "Plan Rows": 30,
          "Plan Width": 0,
          "Index Cond": "(ancestry = concat(geolocations.ancestry, '/', geolocations.id))"
        }
      )
    },
    "JIT": {
      "Worker Number": -1,
      "Functions": 8,
      "Options": {
        "Inlining": true,
        "Optimization": true,
        "Expressions": true,
        "Deforming": true
      }
    }
  }
)

While combining them with a union takes 1 sec 916 ms

SELECT * FROM geolocations
WHERE EXISTS (
   SELECT 1 FROM geolocations g2
   WHERE g2.ancestry = 
      CONCAT(geolocations.ancestry, '/', geolocations.id)
) UNION SELECT * FROM geolocations WHERE location_type = 2

Explain

(
  {
    "Plan": {
      "Node Type": "Unique",
      "Parallel Aware": false,
      "Startup Cost": 308693.44,
      "Total Cost": 332506.74,
      "Plan Rows": 865938,
      "Plan Width": 188,
      "Plans": (
        {
          "Node Type": "Sort",
          "Parent Relationship": "Outer",
          "Parallel Aware": false,
          "Startup Cost": 308693.44,
          "Total Cost": 310858.29,
          "Plan Rows": 865938,
          "Plan Width": 188,
          "Sort Key": (
            "geolocations.id",
            "geolocations.name",
            "geolocations.location_type",
            "geolocations.pricing",
            "geolocations.ancestry",
            "geolocations.geolocationable_id",
            "geolocations.geolocationable_type",
            "geolocations.created_at",
            "geolocations.updated_at",
            "geolocations.info"
          ),
          "Plans": (
            {
              "Node Type": "Append",
              "Parent Relationship": "Outer",
              "Parallel Aware": false,
              "Startup Cost": 15851.41,
              "Total Cost": 63464.05,
              "Plan Rows": 865938,
              "Plan Width": 188,
              "Subplans Removed": 0,
              "Plans": (
                {
                  "Node Type": "Hash Join",
                  "Parent Relationship": "Member",
                  "Parallel Aware": false,
                  "Join Type": "Inner",
                  "Startup Cost": 15851.41,
                  "Total Cost": 35074.94,
                  "Plan Rows": 299882,
                  "Plan Width": 68,
                  "Inner Unique": true,
                  "Hash Cond": "(concat(geolocations.ancestry, '/', geolocations.id) = (g2.ancestry)::text)",
                  "Plans": (
                    {
                      "Node Type": "Seq Scan",
                      "Parent Relationship": "Outer",
                      "Parallel Aware": false,
                      "Relation Name": "geolocations",
                      "Alias": "geolocations",
                      "Startup Cost": 0,
                      "Total Cost": 13900.63,
                      "Plan Rows": 599763,
                      "Plan Width": 68
                    },
                    {
                      "Node Type": "Hash",
                      "Parent Relationship": "Inner",
                      "Parallel Aware": false,
                      "Startup Cost": 15600.65,
                      "Total Cost": 15600.65,
                      "Plan Rows": 20061,
                      "Plan Width": 12,
                      "Plans": (
                        {
                          "Node Type": "Aggregate",
                          "Strategy": "Hashed",
                          "Partial Mode": "Simple",
                          "Parent Relationship": "Outer",
                          "Parallel Aware": false,
                          "Startup Cost": 15400.04,
                          "Total Cost": 15600.65,
                          "Plan Rows": 20061,
                          "Plan Width": 12,
                          "Group Key": (
                            "(g2.ancestry)::text"
                          ),
                          "Plans": (
                            {
                              "Node Type": "Seq Scan",
                              "Parent Relationship": "Outer",
                              "Parallel Aware": false,
                              "Relation Name": "geolocations",
                              "Alias": "g2",
                              "Startup Cost": 0,
                              "Total Cost": 13900.63,
                              "Plan Rows": 599763,
                              "Plan Width": 12
                            }
                          )
                        }
                      )
                    }
                  )
                },
                {
                  "Node Type": "Seq Scan",
                  "Parent Relationship": "Member",
                  "Parallel Aware": false,
                  "Relation Name": "geolocations",
                  "Alias": "geolocations_1",
                  "Startup Cost": 0,
                  "Total Cost": 15400.04,
                  "Plan Rows": 566056,
                  "Plan Width": 68,
                  "Filter": "(location_type = 2)"
                }
              )
            }
          )
        }
      )
    },
    "JIT": {
      "Worker Number": -1,
      "Functions": 15,
      "Options": {
        "Inlining": false,
        "Optimization": false,
        "Expressions": true,
        "Deforming": true
      }
    }
  }
)

My question is, why does postgresql execute the OR query much slower?

Bank statement requirements for student visa in Netherlands

I am a Chinese student who is going to study in Amsterdam in September. I am likely to travel from the UK, where I am currently studying.

On the website, where it asks for evidence of financial support, it mentions requiring a number of things on my sponsor’s bank statement, and ends in “email and/or website” (of the bank). I cannot get a bank statement with this – it seems like quite an odd request, I have asked some friends and most of their statements do not have either of these things on it. I am wondering if anyone has any experience with this – are they strict with this or will it be okay if I submit a bank statement without this?

java – My code seems to be skipping the return statement

I am wiriting a palindrome-checking boolean function in Java – I am learning recursion. When the word is stripped to the final (inner) one or two letters and the program should check if the two letters are the same it seems to not work – function always returns false.
It seems odd that when program comes to return, it just continues to work – I know this because it continues to print my checkpoints (print statements). The print function is executed, but the return statement right after is ignored. And even when the function should return true (=the word is a palindrome), at the end it still returns false.

I have already tried combinations of if, if-else statements, different positions of return statements, the function isPalindrome is working correctly with the main function and I have tried lots of debugging with print functions.

My code:

public static boolean isPalindrome(String word) {
    int wlength = word.length();
    System.out.printf("wlength = %d%n", wlength);
    
    if (wlength == 1) {
        System.out.printf("wlength == 1!!!!%n");
        return true;

    } else if (wlength == 2) {
        System.out.printf("wlength == 2%n");
        String first = word.substring(0, 1);
        String last = word.substring(1, 2);
        if (first == last) {
            return true;
        } else {
            return false;
        }
    }

    String first = word.substring(0, 1);
    String last = word.substring(wlength-1, wlength);
    System.out.printf("first = %s, last = %s %n", first, last);
    if (prva.compareTo(last) == 0) {
        System.out.printf("first == last%n");
        String inner= word.substring(1, wlength-1);
        System.out.printf("new Word = %s RECURSION%n", inner);
        isPalindrome(inner);
    } 
    System.out.println("END");
    return false;
    
}

Thanks!

How to set multiple json attribute in single set statement in karate api?

In Karate Api feature file, I want to set multiple Json attributes in single line, can we do that?

example:
I want set below details in single line

  • set firstName = ”
    And set lastName = ”
    And set age =”

postgresql – Why is OR statement slow in postgres when used with EXISTS

I have a table with 600000 records. My query is filtering by two columns one being indexed and it’s called ancestry and the other being type and it has 3 values (1,2,3) and it is not indexed.

When running the first part alone it takes 1 second to get the results. The query being:

SELECT * FROM geolocations
WHERE EXISTS (
   SELECT 1 FROM geolocations g2
   WHERE g2.ancestry = 
      CONCAT(geolocations.ancestry, '/', geolocations.id)
)

The other query runs in 0.7 seconds:

SELECT * FROM geolocations
WHERE location_type = 2

When combining both queried with an OR it takes around 70 seconds to finish if it ever finishes. I ended up using a union and it returns result in less than 2 seconds which is logical to me.

My question is, what exactly in the way postgres executes the original OR query that makes it this slow?

logic – Proof of statement with empty hypothesis

Let’s say I have these two propositions:

Prop A. “If $x in mathbb{R}$ such that $x^2=-1$ then $3x^2$ is invertible (that means, $3x^2 neq 0$)”

Prop B. “If $x in mathbb{R}$ such that $x^2=-1$ then $3x^2$ is singular (not invertible)”

I want to ask about the correctness of these proofs:

Proof 1.A and 1.B: There is no $x in mathbb{R}$ such that $x^2 = -1$, so no matter what the thesis says, the proposition is true, as there will be no counterexample.

Proof 2.A: Suposing $xin mathbb{R}$ such that $x^2 = -1$, we have that $3x^2 = 3(-1) = -3 neq 0$, so proposition $A$ is true.

Proof 3.B: Suposing $xin mathbb{R}$ such that $x^2 = -1$, we have that $3x^2 = 3(-1) = -3 neq 0$, so $3x^2$ is not singular and proposition $B$ is false.

Obviously, they can not all be right. I think Proof 3.B is wrong. ┬┐But is proof 2.A right? Because it’s basically using the same method (ignoring that no such $x$ exists, and using the hypothesis)