diff --git a/6a4a9ef7-bfbf-40fb-9848-40cf995e2c01.dmp b/6a4a9ef7-bfbf-40fb-9848-40cf995e2c01.dmp deleted file mode 100644 index 46b9026..0000000 Binary files a/6a4a9ef7-bfbf-40fb-9848-40cf995e2c01.dmp and /dev/null differ diff --git a/README.md b/README.md index 609f151..d3fb5d2 100644 --- a/README.md +++ b/README.md @@ -146,35 +146,35 @@ __________________ -##[html: Basic Questions for Begginers](http://www.thatjsdude.com/interview/html.html) +##[html: Basic Questions for Beginners](http://www.thatjsdude.com/interview/html.html) 15 basic questions and asnwers ______ -1. Why do u need doctype? -2. What is the use of data-* attribute? -3. How can you generate public key in html? -4. How do you change direction of html text? +1. Why do you need doctype? +2. What are data-* attributes used for? +3. How can you generate a public key in html? +4. How do you change the direction of html text? 5. How can you highlight text in html? 6. Can you apply css to a part of html document only? -7. Will browser make http request for the following cases? +7. Will a browser make http request for the following cases? 8. Which resource would be downloaded first? -9. What is optional tag? +9. What is an optional tag? 10. What are the differences between div and span? -11. How would you differentiate div, section and article? -12. How to select svg or canvas for your site? +11. How would you differentiate between div, section, and article? +12. How would you select svg or canvas for your site? 13. How to serve html in multiple languages? 14. Explain standard and quirks mode. -15. What is semantic tag? +15. What is a semantic tag? ####[HTML: Answers for Basic Questions](http://www.thatjsdude.com/interview/html.html) -##[JavaScript: LinkedList (part -4: work in porcess)](http://www.thatjsdude.com/interview/linkedList.html) +##[JavaScript: LinkedList (part 4: work in process)](http://www.thatjsdude.com/interview/linkedList.html) Very rough stage..need to finish (for intermediate) -##[JavaScript: search and Sort (part -5: work in porcess)](http://khan4019.github.io/front-end-Interview-Questions/sort.html) +##[JavaScript: search and Sort (part 5: work in process)](http://khan4019.github.io/front-end-Interview-Questions/sort.html) Very rough stage..need to finish (for expert) -##[JavaScript: Binary Search Tree (part -6: work in porcess)](http://khan4019.github.io/front-end-Interview-Questions/bst.html) +##[JavaScript: Binary Search Tree (part 6: work in process)](http://khan4019.github.io/front-end-Interview-Questions/bst.html) Very rough stage..need to finish (for expert) __________________ diff --git a/bst.html b/bst.html index a216086..8f7fb42 100644 --- a/bst.html +++ b/bst.html @@ -120,7 +120,20 @@
Question: How do you implement Breadth First Search
Answer:
-
+BinarySearchTree.prototype.breadthFirstSearch = function() {
+ var queue = [];
+ queue.push(this);
+ while (queue.length) {
+ var node = queue.shift();
+ console.log(node.value);
+ if (node.left) {
+ queue.push(node.left);
+ }
+ if (node.right) {
+ queue.push(node.right);
+ }
+ }
+};
ref: stackoverflow
ref: js algorithms
diff --git a/html.html b/html.html index e54f499..badeb7c 100644 --- a/html.html +++ b/html.html @@ -137,7 +137,7 @@Question: Can u apply css rule to a part of html document?
-Answer: yes. by using "scopped" in the style tag.
+Answer: yes. by using "scoped" in the style tag.
ref MDN: styleQuestion: What are the differences between ==
and ===
?
Answer: The simplest way of saying that, == will not check types and === will check whether both sides are of same type. So, == is tolerant. But under the hood it converts to its convenient type to have both in same type and then do the comparison.
-=== compares the types and values. Hence, if both sides are not same type, answer is always false. For example, if you are comparing two strings, they must have identical character sets. For other primitives (number, boolean) must share the same value.
-Rule for implicit coercion: Comparison by using == does implicit type conversion under the hood. And rules for implicit coercion are as follows-
+Answer: The simplest way of saying it is that == will not check types and === will check whether both sides are of the same type. So, == is tolerant. But under the hood it converts to a convenient type, in order to have both as the same type, and then does the comparison.
+=== compares the types and values. Hence, if both sides are not same type, the answer is always false. For example, if you are comparing two strings, they must have identical character sets. For other primitives (number, boolean), they must share the same value.
+Rule for implicit coercion: Comparison by using == does implicit type conversion under the hood. The rules for implicit coercion are as follows-
Be careful while comparing objects, identifiers must reference the same objects or same array.
+Be careful while comparing objects — identifiers must reference the same objects or same array.
var a = {a: 1};
var b = {a: 1};
@@ -185,7 +185,7 @@ 2. == Vs ===
3. Object Equality
Question: How would you compare two objects in JavaScript?
Basics: JavaScript has two different approaches for testing equality. Primitives like strings and numbers are compared by their value, while objects like arrays, dates, and user defined objects are compared by their reference. This means it compares whether two objects are referring to the same location in memory.
- Answer: Equality check will check whether two objects have same value for same property. To check that, you can get the keys for both the objects. If the number of properties doesn't match, these two objects are not equal. Secondly, you will check each property whether they have the same value. If all the properties have same value, they are equal.
+ Answer: Equality check will check whether two objects have the same value for the same property. To check that, you can get the keys for both the objects. If the number of properties doesn't match, these two objects are not equal. Secondly, you will check whether each property has the same value in both objects. If all the properties have the same value, they are equal.
function isEqual(a, b) {
var aProps = Object.getOwnPropertyNames(a),
@@ -238,7 +238,7 @@ True False Rapid Fire
Question: Boolean(/foo/)
Answer: true
Question: true%1
- Answer: 0. When you are trying to find reminder of true, true becomes 1 and reminder of 1 while dividing by 1 is 0. you will get same result if you doe false%1
+ Answer: 0. When you are trying to find reminder of true, true becomes 1 and reminder of 1 while dividing by 1 is 0. You will get same result if you do false%1
Question: ''%1
Answer: 0
Question: As []
is true, []==true
should also be true. right?
Answer: You are right about first part, []
, empty array is an object and object is always truthy. Hence, if you use if([]){console.log('its true')}
you will see the log.
However, special case about ==
(double equal) is that it will do some implicit coercion.
Since left and right side of the equality are two different types, JavaScript can't compare them directly . Hence, under the hood, JavaScript will convert them to compare. first right side of the equality will be cooereced to a number and number of true
would be 1.
After that, JavaScript implementation will try to convert []
by usingtoPrimitive
(of JavaScript implementation). since [].valueOf
is not primitive will use toString
and will get ""
Now you are comparing "" == 1 and still left and right is not same type. Hence left side will be converted again to a number and empty string will be 0.
-Finally, they are of same type, you are comparing 0 === 1
which will be false.
Since the left and right sides of the equality are two different types, JavaScript can't compare them directly. Hence, under the hood, JavaScript will convert them to compare. First, the right side of the equality will be cooereced to a number and number of true
would be 1.
After that, JavaScript implementation will try to convert []
by usingtoPrimitive
(of JavaScript implementation). Since [].valueOf
is not primitive, it will use toString
and will get ""
Now you are comparing "" == 1 and still, the left and right are not the same type. Hence, the left side will be converted again to a number and empty string will be 0.
+Finally, they are of same type. You are comparing 0 === 1
which will be false.
ref: angus croll: truth and eqality in JS, ref: truthy and falsy
Question: How could you write a method on instance of a date which will give you next day?
+Question: How could you write a method on an instance of a date which will give you the next day?
Answer: I have to declare a method on the prototype of Date object. To get access to the current value of the instance of the date, i will use this
Date.prototype.nextDay = function(){
diff --git a/js3.html b/js3.html
index 59d555b..a827e1b 100644
--- a/js3.html
+++ b/js3.html
@@ -434,6 +434,13 @@ algorithm related Question (will some future blog)
Medium level question for js3
+ - Define a function that returns n lines of Pascal’s Triangle. (this question was the entire interview)
+ - Define a function that takes an array of strings, and returns the most commonly occurring string that array (this question came with an execution time limit)
+ - Use recursion to log a fibonacci sequence of n length.
+ - Explain the use cases for, and differences between — bind, apply and call.
+ - What is the event loop?
+ - Which new JavaScript / browser features are you most excited about and why?
+ - What are the differences between functional and imperative programming styles, and explain your preference, if any.
- what is same origin policy with regards to JS
- ~~3.14 ?? what and why. answer here or great mystery of tilde
- difference between cookies, sessionStorage and local storage
diff --git a/todo.html b/todo.html
new file mode 100644
index 0000000..2e21b2f
--- /dev/null
+++ b/todo.html
@@ -0,0 +1,3 @@
+
+ - read this here
+