From 4fd59a4123cbe0f0a15872a4f8c60fd93d0fe9b7 Mon Sep 17 00:00:00 2001 From: bhushanhr26 <58306435+bhushanhr26@users.noreply.github.com> Date: Mon, 22 Aug 2022 01:48:00 +0530 Subject: [PATCH 1/6] Merge branch 'master' of https://github.com/pesto-students/p4-tanish-bhushanhr26 into week-5 --- Week-4/Assignement 4.2/js/index.js | 27 +++++++++++++++++++++++++++ Week-4/Assignment 4.1/js/index.js | 20 ++++++++++++++++++++ Week-4/Assignment 4.3/Index.js | 18 ++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 Week-4/Assignement 4.2/js/index.js create mode 100644 Week-4/Assignment 4.1/js/index.js create mode 100644 Week-4/Assignment 4.3/Index.js diff --git a/Week-4/Assignement 4.2/js/index.js b/Week-4/Assignement 4.2/js/index.js new file mode 100644 index 0000000..ac4826c --- /dev/null +++ b/Week-4/Assignement 4.2/js/index.js @@ -0,0 +1,27 @@ + +var Person = function() {}; + +Person.prototype.initialize = function(name, age) +{ + this.name = name; + this.age = age; +} + +var Teacher = function() {}; +Teacher.prototype = new Person(); + +Teacher.prototype.teach = function(subject) +{ + console.log(this.name + " is now teaching " + subject); +} + +var me = new Teacher(); + +me.initialize("John", 25); +me.teach("Inheritance"); + +me.initialize("Bhushan", 22); +me.teach("Polymorphism"); + +me.initialize("Samarpan", 23); +me.teach("Nothing"); \ No newline at end of file diff --git a/Week-4/Assignment 4.1/js/index.js b/Week-4/Assignment 4.1/js/index.js new file mode 100644 index 0000000..a6e7897 --- /dev/null +++ b/Week-4/Assignment 4.1/js/index.js @@ -0,0 +1,20 @@ +function getNumber() { + let x = Math.random(); + let y = x.toFixed(2) + return new Promise(function (resolve, reject) { + if (y/5===0) { + reject("It is Divisible by 5"); + return; + } + + resolve(y); + }); +} +getNumber() + .then(function (result) { + console.log(`success ${result}`); + }) + .catch(function (error) { + console.log("error"); + console.log(error); + }); diff --git a/Week-4/Assignment 4.3/Index.js b/Week-4/Assignment 4.3/Index.js new file mode 100644 index 0000000..f6d8ce3 --- /dev/null +++ b/Week-4/Assignment 4.3/Index.js @@ -0,0 +1,18 @@ +const fibonaci = (n)=>({ + [Symbol.iterator]:()=>{ + let i =1; + let old =0,new1 = 0; + return { + next:()=>{ + if(i++<=n){ + [old,new1] = [new1,(old+new1)||1]; + return {value:old,done:false} + } + else{ + return{done:true} + } + } + } + } +}) +console.log([...fibonaci(6)]); \ No newline at end of file From 5dc2a471d2c14fa141e22884aa625dbd50ba8955 Mon Sep 17 00:00:00 2001 From: bhushanhr26 <58306435+bhushanhr26@users.noreply.github.com> Date: Tue, 23 Aug 2022 22:56:33 +0530 Subject: [PATCH 2/6] Assignment 6.3 --- Week-6/Assignment-6.3/index.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Week-6/Assignment-6.3/index.js diff --git a/Week-6/Assignment-6.3/index.js b/Week-6/Assignment-6.3/index.js new file mode 100644 index 0000000..255141f --- /dev/null +++ b/Week-6/Assignment-6.3/index.js @@ -0,0 +1,5 @@ +const arr = [0, 2, 1, 2, 0]; +arr.sort(function(a, b) { + return a - b; + }); +console.log(arr); From 08aaa6fcbf073aa3444b0fa07b289bc79725e31d Mon Sep 17 00:00:00 2001 From: bhushanhr26 <58306435+bhushanhr26@users.noreply.github.com> Date: Tue, 23 Aug 2022 22:58:45 +0530 Subject: [PATCH 3/6] Assignment 6.3 completed --- Week-6/Assignment-6.3/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Week-6/Assignment-6.3/index.js b/Week-6/Assignment-6.3/index.js index 255141f..2db9679 100644 --- a/Week-6/Assignment-6.3/index.js +++ b/Week-6/Assignment-6.3/index.js @@ -1,5 +1,6 @@ +//const arr = [0,1,0]; const arr = [0, 2, 1, 2, 0]; -arr.sort(function(a, b) { - return a - b; - }); +arr.sort(function (a, b) { + return a - b; +}); console.log(arr); From d4ec4f68b51e276076d80b0229fe4b194480120d Mon Sep 17 00:00:00 2001 From: bhushanhr26 <58306435+bhushanhr26@users.noreply.github.com> Date: Wed, 24 Aug 2022 00:31:58 +0530 Subject: [PATCH 4/6] Assingment 6.1 completed --- Week-6/Assignment-6.1/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Week-6/Assignment-6.1/index.js diff --git a/Week-6/Assignment-6.1/index.js b/Week-6/Assignment-6.1/index.js new file mode 100644 index 0000000..376a88b --- /dev/null +++ b/Week-6/Assignment-6.1/index.js @@ -0,0 +1,10 @@ +function longestSubArray(arr) { + let a = arr[0]; + for (let i = 1; i < arr.length; i++) { + arr[i] = Math.max(arr[i], arr[i] + arr[i - 1]); + a = Math.max(a,arr[i]) + } + return a +} +console.log(longestSubArray([1,2,3,4,-10])); +console.log(longestSubArray([-2,1,-3,4,-1,2,1,-5,4])); From 52fd9ed730cbb062a0c03f01cec10bc67e39120b Mon Sep 17 00:00:00 2001 From: bhushanhr26 <58306435+bhushanhr26@users.noreply.github.com> Date: Wed, 24 Aug 2022 02:13:48 +0530 Subject: [PATCH 5/6] Assignment 6.5 completed --- Week-6/Assignment-6.5/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Week-6/Assignment-6.5/index.js diff --git a/Week-6/Assignment-6.5/index.js b/Week-6/Assignment-6.5/index.js new file mode 100644 index 0000000..8577d46 --- /dev/null +++ b/Week-6/Assignment-6.5/index.js @@ -0,0 +1,12 @@ +function arrDifference(arr, B) { + for (i = 0; i < arr.length - 1; i++) { + for (j = i + 1; j < arr.length; j++) { + if (arr[j] - arr[i] == B) { + return 1; + } + } + } + return 0; +} +console.log(arrDifference([5, 10, 3, 2, 50, 80], 78)); +console.log(arrDifference([-10,20], 30)); From 90b12f6c525844d6f1e9dd86ddc81c8cbd594c57 Mon Sep 17 00:00:00 2001 From: bhushanhr26 <58306435+bhushanhr26@users.noreply.github.com> Date: Mon, 29 Aug 2022 22:39:34 +0530 Subject: [PATCH 6/6] The Assignment 6.6 completed --- Week-6/Assignment-6.6/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Week-6/Assignment-6.6/index.js diff --git a/Week-6/Assignment-6.6/index.js b/Week-6/Assignment-6.6/index.js new file mode 100644 index 0000000..d13ea47 --- /dev/null +++ b/Week-6/Assignment-6.6/index.js @@ -0,0 +1,14 @@ +function triplet(arr, x) { + let closestSum = Number.MAX_VALUE; + + for (let i = 0; i < arr.length; i++) { + for (let j = i + 1; j < arr.length; j++) { + for (let k = j + 1; k < arr.length; k++) { + if (Math.abs(x - closestSum) > Math.abs(x - (arr[i] + arr[j] + arr[k]))) + closestSum = arr[i] + arr[j] + arr[k]; + } + } + } + return closestSum; +} +console.log(triplet([-1, 2, 1, -4], 1));