Skip to content

Commit

Permalink
Merge branch 'master' into contrib
Browse files Browse the repository at this point in the history
  • Loading branch information
ambujraj authored Oct 19, 2018
2 parents ec3439c + 410b501 commit 1310378
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Binary-Search-c++/binarysearch_basic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include<bits/stdc++.h>

using namespace std;

int main()
{
int n, i, arr[50], el, low, high, mid;
cout << "Enter size of list:";
cin >> n;
cout << "Enter elements :";
for (i=0; i<n; i++)
{
cin >> arr[i];
}
cout << "Enter element to be searched:";
cin >> el;
low = 0;
high = n-1;
mid = (low+high)/2;
while (low <= high)
{
if(arr[mid] < el)
{
low = mid + 1;

}
else if(arr[mid] == el)
{
cout << el <<" found at location " << mid <<"\n";
break;
}
else
{
high = mid - 1;
}
mid = (low + high)/2;
}
if(low > high)
{
cout << "Not found! " << el << " is not present in the list.";
}

return 0;
}
12 changes: 12 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1718,3 +1718,15 @@ Place: Italy
About: Junior Software Engineer
Programming Language: C, C++, Java, C#, Python, Scala
Email: [email protected]

Name : Rahul Mishra
Place : Noida(India)
About : B.Tech(CSE) student
Programming Language : C
Email : [email protected]

Name : [Trishla Verma](https://github.com/trishla08)<br/>
Place : New Delhi , India <br/>
About : Coding Enthusiast | Computer Engineering Student
Programming Languages : C, C++, Java, Javascript
Email : [email protected]
36 changes: 36 additions & 0 deletions CommonjsinterviewQuestions/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

/* I will add here every day one or two common js interview questions and there respective answers which would
help u gain confidence and also to ace or hone up your JS skills
*/
let obj = {
a:5,
b:function(){
console.log(this.a);
},
c:()=>{
console.log(this.a);
}
};

let f1 = obj.b;
let f2 = obj.c;
f1();
f2();

obj.b();
obj.c();


//So, answer of this above four function calling will be as follows with their explanation =>

f1() // this will print "undefined" as in after obj.b, f1 is now referencing global object window not object obj
// this.a will print undefined as with window object there is no a property defined.
f2() // this will also print "undefined" as in arrow functions "this" will refer "this" of surrounding scope
// as in arrow function "this" doesn't not get bind so if we want to know the value of this we should see
// the this just above the line we have start declaring our arrow function.Hence here "this" is referring to
// window object that's why it doesn't has any 'a' property defined with it.

obj.b() // here it will print '5' as in regular function calling b method will get bind to object left of dot

obj.c() // here also it will print "undefined" as in arrow function this doesn't get bind and it will see "this" of surrounding scope
// which is referring to window object and that object not have any 'a' property defined with it

0 comments on commit 1310378

Please sign in to comment.