Content-Length: 2867 | pFad | http://github.com/TheAlgorithms/JavaScript/pull/1753.patch
thub.com
From bcb68018fb00de45fcb0c9e99443f57b2bbc9694 Mon Sep 17 00:00:00 2001
From: Hridyanshu7
Date: Fri, 25 Oct 2024 12:27:07 +0530
Subject: [PATCH 1/2] test: added for Linear Search Algorithm
---
Search/LinearSearch.js | 2 ++
Search/test/LinearSearch.test.js | 35 ++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)
create mode 100644 Search/test/LinearSearch.test.js
diff --git a/Search/LinearSearch.js b/Search/LinearSearch.js
index 637ebc1589..ccd0fc7b51 100644
--- a/Search/LinearSearch.js
+++ b/Search/LinearSearch.js
@@ -3,6 +3,8 @@
* value within a list. It sequentially checks each element of the list
* for the target value until a match is found or until all the elements
* have been searched.
+ *
+ * [Reference](https://en.wikipedia.org/wiki/Linear_search)
*/
function SearchArray(searchNum, ar, output = (v) => console.log(v)) {
const position = Search(ar, searchNum)
diff --git a/Search/test/LinearSearch.test.js b/Search/test/LinearSearch.test.js
new file mode 100644
index 0000000000..d593d9aa1c
--- /dev/null
+++ b/Search/test/LinearSearch.test.js
@@ -0,0 +1,35 @@
+import { Search as linearSearch } from '../LinearSearch'
+
+const tests = [
+ {
+ test: {
+ arr: [1, 2, 300, 401, 450, 504, 800, 821, 855, 900, 1002],
+ target: 900
+ },
+ expectedValue: 9
+ },
+ {
+ test: {
+ arr: [1, 104, 110, 4, 44, 55, 56, 78],
+ target: 104
+ },
+ expectedValue: 1
+ },
+ {
+ test: {
+ arr: [-4, 5, 50, 77, 821, 85, 99, 100],
+ target: 192
+ },
+ expectedValue: -1
+ }
+]
+
+describe('Linear Search', () => {
+ it.each(tests)(
+ 'linearSearch($test.arr, $test.target) => $expectedValue',
+ ({ test, expectedValue }) => {
+ const { arr, target } = test
+ expect(linearSearch(arr, target)).toBe(expectedValue)
+ }
+ )
+})
From cbea1feeb2336c22c59e77b076196513e7b64ecd Mon Sep 17 00:00:00 2001
From: Hridyanshu <124202756+HRIDYANSHU054@users.noreply.github.com>
Date: Mon, 18 Nov 2024 18:57:00 +0530
Subject: [PATCH 2/2] Update Search/LinearSearch.js
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
---
Search/LinearSearch.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Search/LinearSearch.js b/Search/LinearSearch.js
index ccd0fc7b51..96a9d1fa34 100644
--- a/Search/LinearSearch.js
+++ b/Search/LinearSearch.js
@@ -4,7 +4,7 @@
* for the target value until a match is found or until all the elements
* have been searched.
*
- * [Reference](https://en.wikipedia.org/wiki/Linear_search)
+ * @see https://en.wikipedia.org/wiki/Linear_search
*/
function SearchArray(searchNum, ar, output = (v) => console.log(v)) {
const position = Search(ar, searchNum)
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/TheAlgorithms/JavaScript/pull/1753.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy