Beruflich Dokumente
Kultur Dokumente
2. Question 2:
- For better readable I really want split this method to two parts. My idea is we
will generate random number and then find a prime number less than it. I think it
gets better performance than two following ways:
- We get all prime number less than 100 and then get random from them.
- Random many times and stop random when it is a prime number.
return true;
}
return 2;
}
4. Question 4:
SELECT Date, ServiceType, Rating
FROM (SELECT Date, ServiceType, Rating,
row_number() over(partition by ServiceType order by Date desc) as rn
FROM ServiceRating) AS T
WHERE rn = 1
6. Question 6:
- Result is 1.
- Inside the function2 "myVar" always has value is 1 because this is local
scope. You can imagine this just is pass-by-value in the others strongly-typed
programming languages like C#, java etc.
7. Question 7:
- If you still want to keep your question then the result is 1.
- If you change function4 to my function above then the result is 2.
- In JavaScript it's always pass-by-value, but for objects the value of the
variable is a copy-reference.
- Please look at my function4 above: When the function4 is called, we get the
result is "2", because in JavaScript objects are always passed by copy-
reference this mean you can change objects properties value in the
function3 and then get there changed when the function3 is done executing,
but if you re-assign the object inside of the function3, this will not be visible
outside of the function3 since it was only a copy of the reference you changed.
8. Question 8:
- Explained above.