Possible Duplicate:
Can somebody explain this Javascript method ?
(x = [].reverse)() === window // true
Any idea why?
A set of parenthesis are duplicate if the same subexpression is surrounded by multiple parenthesis. Examples: Below expressions have duplicate parenthesis - ((a+b)+((c+d))) The subexpression "c+d" is surrounded by two pairs of brackets. (((a+(b)))+(c+d)) The subexpression "a+(b)" is surrounded by two pairs of brackets.
Find the Duplicate Number. Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is only one repeated number in nums , return this repeated number. You must solve the problem without modifying the array nums and uses only constant extra space.
The idea is to use stack. Iterate through the given expression and for each character in the expression, if the character is a open parenthesis '(' or any of the operators or operands, push it to the top of the stack.
(x=[].reverse)() === window // true
Didn't understand this one at first, but I guess it is easy: first x becomes the reverse function of arrays, then it is called with
this === window
. So it amounts towindow.reverse()
. Just looked it up, and reverse() works in place, sowindow.reverse() === window
- although it is potentially different from before.
I got this answer from this link
http://news.ycombinator.com/item?id=1122004
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With