From 0f5b2e8f5c355f09f6bc424ac51a876d9fd8a6ec Mon Sep 17 00:00:00 2001 From: ProgrammerDATCH Date: Wed, 14 Feb 2024 11:28:00 +0200 Subject: [PATCH] #2 --- .gitignore | 1 - JavascriptFunctions/ArrayManipulation.js | 39 +++++++++++++++++++++ index.html | 43 +++++++++++++++++++----- 3 files changed, 74 insertions(+), 9 deletions(-) delete mode 100644 .gitignore create mode 100644 JavascriptFunctions/ArrayManipulation.js diff --git a/.gitignore b/.gitignore deleted file mode 100644 index f5c5d7e..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -interview.js \ No newline at end of file diff --git a/JavascriptFunctions/ArrayManipulation.js b/JavascriptFunctions/ArrayManipulation.js new file mode 100644 index 0000000..54c9f48 --- /dev/null +++ b/JavascriptFunctions/ArrayManipulation.js @@ -0,0 +1,39 @@ +// console.log("Hello, World!"); +function calculateAverageInArray(arr) { + let sum = 0; + for (let i = 0; i < arr.length; i++) { + sum += arr[i]; + } + let average = sum / arr.length; + return average; +} + + +let arr1 = [6, 1, 3, 5, 9, 10, -1]; +console.log(get2LargeNumbers(arr1)); + + +function get2LargeNumbers(arr) { + let firstLargeNumber = arr[0]; + let firstLargeNumberIndex = 0; + //getting first large Number in the array + for (let i = 0; i < arr.length; i++) { + if (arr[i] > firstLargeNumber) { + firstLargeNumber = arr[i]; + firstLargeNumberIndex = i; + } + } + //getting the second large number in the array + let secondLargeNumber = (firstLargeNumberIndex == 0) ? arr[1] : arr[0]; + + for (let i = 0; i < arr.length; i++) { + if (firstLargeNumberIndex != i) { + if (arr[i] > secondLargeNumber) { + secondLargeNumber = arr[i]; + } + } + } + + let resultArr = [firstLargeNumber, secondLargeNumber]; + return resultArr; +} \ No newline at end of file diff --git a/index.html b/index.html index 17f04e5..46fd5af 100644 --- a/index.html +++ b/index.html @@ -5,19 +5,28 @@ All Andela Works @@ -48,12 +69,18 @@

All Andela Works

SnapChat Login Page

This is a SnapChat Login Page designed with HTML, CSS and JavaScript.

- View Project +
- + +