From c32e00810feb2bf7b038ccc777f3a4ba67646753 Mon Sep 17 00:00:00 2001 From: satyam8254 Date: Mon, 29 Nov 2021 19:27:10 +0530 Subject: [PATCH 1/3] JavaScript Assignment 5 create object --- assignments/create_object/create_object.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/assignments/create_object/create_object.js b/assignments/create_object/create_object.js index 775bc8c..a544cf4 100644 --- a/assignments/create_object/create_object.js +++ b/assignments/create_object/create_object.js @@ -1,5 +1,11 @@ function CreateObject(arr) { // Write your code here + var res = {}; + for (var i = 0; i < arr.length; i = i + 2) { + res[arr[i]] = arr[i + 1] + } + return res + } -module.exports = CreateObject; +module.exports = CreateObject; \ No newline at end of file From 59a85453dde2f849731959474bfb969a769baf39 Mon Sep 17 00:00:00 2001 From: satyam8254 Date: Mon, 29 Nov 2021 19:47:25 +0530 Subject: [PATCH 2/3] c --- assignments/create_object/CreateObject.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignments/create_object/CreateObject.md b/assignments/create_object/CreateObject.md index b26685c..bf82f90 100644 --- a/assignments/create_object/CreateObject.md +++ b/assignments/create_object/CreateObject.md @@ -10,7 +10,7 @@ Instructions ```bash Example: Input - ["firstName", "Yash", "lastName": "Goyal"] -Output - { firstName: "Yash", lastName: "Goyal" } +Output - { firstName: "Yash", lastName: "Goral" } ``` Run ```npm run test:file create_object``` to test your code \ No newline at end of file From a9c5b442e93720d2ba87f49b0bab40794b8d6aca Mon Sep 17 00:00:00 2001 From: satyam8254 Date: Tue, 30 Nov 2021 15:04:49 +0530 Subject: [PATCH 3/3] JavaScript Assignment-6 play with array --- .../play_with_array/play_with_array.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/assignments/play_with_array/play_with_array.js b/assignments/play_with_array/play_with_array.js index 0601c6f..523302b 100644 --- a/assignments/play_with_array/play_with_array.js +++ b/assignments/play_with_array/play_with_array.js @@ -7,6 +7,14 @@ function getEven(arr) { Write you code below */ + var res = []; + for (var i = 0; i < arr.length; i++) { + if (arr[i] % 2 == 0) { + res.push(arr[i]) + } + } + return res; + } @@ -18,6 +26,12 @@ function multiplyByN(arr, n) { Output: [3,9,13,165] Write you code below */ + var res = []; + for (var i = 0; i < arr.length; i++) { + res.push(arr[i] * n) + } + return res + } function removeNthElement(arr, n) { @@ -28,6 +42,13 @@ function removeNthElement(arr, n) { Output: [1,3,4,7] Write you code below */ + var res = [] + for (var i = 0; i < arr.length; i++) { + if (i != n) { + res.push(arr[i]) + } + } + return res } module.exports = {