From 46e2b3d2ac25df6d2ec60b13fd3e8ec855ee7858 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Thu, 22 May 2025 11:10:52 -0400 Subject: [PATCH 1/8] Build myEach and myMap functions --- .results.json | 493 ++++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 36 ++++ 2 files changed, 529 insertions(+) create mode 100644 .results.json diff --git a/.results.json b/.results.json new file mode 100644 index 000000000..5d6fc9c49 --- /dev/null +++ b/.results.json @@ -0,0 +1,493 @@ +{ + "stats": { + "suites": 11, + "tests": 27, + "passes": 11, + "pending": 0, + "failures": 16, + "start": "2025-05-22T15:09:48.243Z", + "end": "2025-05-22T15:09:48.367Z", + "duration": 124 + }, + "tests": [ + { + "title": "calls alert with each element passed", + "fullTitle": "index.js myEach calls alert with each element passed", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "calls alert properly on object values", + "fullTitle": "index.js myEach calls alert properly on object values", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns the original collection", + "fullTitle": "index.js myEach returns the original collection", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "successfully returns a correctly populated array", + "fullTitle": "index.js myMap successfully returns a correctly populated array", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "does not modify the original array", + "fullTitle": "index.js myMap does not modify the original array", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "successfully returns a correctly populated array from modified object values", + "fullTitle": "index.js myMap successfully returns a correctly populated array from modified object values", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "does not modify the original object", + "fullTitle": "index.js myMap does not modify the original object", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns the correct reduced value when passed an initial value", + "fullTitle": "index.js myReduce returns the correct reduced value when passed an initial value", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myReduce is not defined\n at Context. (test/indexTest.js:71:29)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myReduce is not defined" + } + }, + { + "title": "returns the correct reduced value when not passed an initial value", + "fullTitle": "index.js myReduce returns the correct reduced value when not passed an initial value", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myReduce is not defined\n at Context. (test/indexTest.js:76:29)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myReduce is not defined" + } + }, + { + "title": "does not modify the original array", + "fullTitle": "index.js myReduce does not modify the original array", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns the correct reduced value from object values", + "fullTitle": "index.js myReduce returns the correct reduced value from object values", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myReduce is not defined\n at Context. (test/indexTest.js:85:25)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myReduce is not defined" + } + }, + { + "title": "does not modify the original object", + "fullTitle": "index.js myReduce does not modify the original object", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns the value if found", + "fullTitle": "index.js myFind returns the value if found", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myFind is not defined\n at Context. (test/indexTest.js:106:7)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myFind is not defined" + } + }, + { + "title": "does not traverse the whole array if the value is found early", + "fullTitle": "index.js myFind does not traverse the whole array if the value is found early", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myFind is not defined\n at Context. (test/indexTest.js:113:7)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myFind is not defined" + } + }, + { + "title": "returns undefined if the value is not present", + "fullTitle": "index.js myFind returns undefined if the value is not present", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myFind is not defined\n at Context. (test/indexTest.js:118:7)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myFind is not defined" + } + }, + { + "title": "correctly filters for values that the callback evaluates as true", + "fullTitle": "index.js myFilter correctly filters for values that the callback evaluates as true", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myFilter is not defined\n at Context. (test/indexTest.js:134:29)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myFilter is not defined" + } + }, + { + "title": "correctly returns an empty array if no matching values are found", + "fullTitle": "index.js myFilter correctly returns an empty array if no matching values are found", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myFilter is not defined\n at Context. (test/indexTest.js:139:29)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myFilter is not defined" + } + }, + { + "title": "correctly returns the size of the collection when an array is passed", + "fullTitle": "index.js mySize correctly returns the size of the collection when an array is passed", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: mySize is not defined\n at Context. (test/indexTest.js:149:7)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "mySize is not defined" + } + }, + { + "title": "correctly returns the size of the collection (amount of keys) when an object is passed", + "fullTitle": "index.js mySize correctly returns the size of the collection (amount of keys) when an object is passed", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: mySize is not defined\n at Context. (test/indexTest.js:153:7)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "mySize is not defined" + } + }, + { + "title": "returns the first element of the collection", + "fullTitle": "index.js myFirst returns the first element of the collection", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myFirst is not defined\n at Context. (test/indexTest.js:161:7)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myFirst is not defined" + } + }, + { + "title": "returns the first n elements of the collection when the second optional argument (n) is provided", + "fullTitle": "index.js myFirst returns the first n elements of the collection when the second optional argument (n) is provided", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myFirst is not defined\n at Context. (test/indexTest.js:165:14)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myFirst is not defined" + } + }, + { + "title": "returns the last element of the collection", + "fullTitle": "index.js myLast returns the last element of the collection", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myLast is not defined\n at Context. (test/indexTest.js:173:7)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myLast is not defined" + } + }, + { + "title": "returns the last n elements of the collection when the second optional argument (n) is provided", + "fullTitle": "index.js myLast returns the last n elements of the collection when the second optional argument (n) is provided", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myLast is not defined\n at Context. (test/indexTest.js:177:14)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myLast is not defined" + } + }, + { + "title": "retrieves all the names of the object's own enumerable properties", + "fullTitle": "index.js myKeys retrieves all the names of the object's own enumerable properties", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myKeys is not defined\n at Context. (test/indexTest.js:241:14)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myKeys is not defined" + } + }, + { + "title": "does not modify the original object", + "fullTitle": "index.js myKeys does not modify the original object", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "retrieves all the values of the object's own properties", + "fullTitle": "index.js myValues retrieves all the values of the object's own properties", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myValues is not defined\n at Context. (test/indexTest.js:254:14)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myValues is not defined" + } + }, + { + "title": "does not modify the original object", + "fullTitle": "index.js myValues does not modify the original object", + "duration": 0, + "currentRetry": 0, + "err": {} + } + ], + "pending": [], + "failures": [ + { + "title": "returns the correct reduced value when passed an initial value", + "fullTitle": "index.js myReduce returns the correct reduced value when passed an initial value", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myReduce is not defined\n at Context. (test/indexTest.js:71:29)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myReduce is not defined" + } + }, + { + "title": "returns the correct reduced value when not passed an initial value", + "fullTitle": "index.js myReduce returns the correct reduced value when not passed an initial value", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myReduce is not defined\n at Context. (test/indexTest.js:76:29)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myReduce is not defined" + } + }, + { + "title": "returns the correct reduced value from object values", + "fullTitle": "index.js myReduce returns the correct reduced value from object values", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myReduce is not defined\n at Context. (test/indexTest.js:85:25)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myReduce is not defined" + } + }, + { + "title": "returns the value if found", + "fullTitle": "index.js myFind returns the value if found", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myFind is not defined\n at Context. (test/indexTest.js:106:7)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myFind is not defined" + } + }, + { + "title": "does not traverse the whole array if the value is found early", + "fullTitle": "index.js myFind does not traverse the whole array if the value is found early", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myFind is not defined\n at Context. (test/indexTest.js:113:7)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myFind is not defined" + } + }, + { + "title": "returns undefined if the value is not present", + "fullTitle": "index.js myFind returns undefined if the value is not present", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myFind is not defined\n at Context. (test/indexTest.js:118:7)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myFind is not defined" + } + }, + { + "title": "correctly filters for values that the callback evaluates as true", + "fullTitle": "index.js myFilter correctly filters for values that the callback evaluates as true", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myFilter is not defined\n at Context. (test/indexTest.js:134:29)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myFilter is not defined" + } + }, + { + "title": "correctly returns an empty array if no matching values are found", + "fullTitle": "index.js myFilter correctly returns an empty array if no matching values are found", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myFilter is not defined\n at Context. (test/indexTest.js:139:29)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myFilter is not defined" + } + }, + { + "title": "correctly returns the size of the collection when an array is passed", + "fullTitle": "index.js mySize correctly returns the size of the collection when an array is passed", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: mySize is not defined\n at Context. (test/indexTest.js:149:7)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "mySize is not defined" + } + }, + { + "title": "correctly returns the size of the collection (amount of keys) when an object is passed", + "fullTitle": "index.js mySize correctly returns the size of the collection (amount of keys) when an object is passed", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: mySize is not defined\n at Context. (test/indexTest.js:153:7)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "mySize is not defined" + } + }, + { + "title": "returns the first element of the collection", + "fullTitle": "index.js myFirst returns the first element of the collection", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myFirst is not defined\n at Context. (test/indexTest.js:161:7)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myFirst is not defined" + } + }, + { + "title": "returns the first n elements of the collection when the second optional argument (n) is provided", + "fullTitle": "index.js myFirst returns the first n elements of the collection when the second optional argument (n) is provided", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myFirst is not defined\n at Context. (test/indexTest.js:165:14)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myFirst is not defined" + } + }, + { + "title": "returns the last element of the collection", + "fullTitle": "index.js myLast returns the last element of the collection", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myLast is not defined\n at Context. (test/indexTest.js:173:7)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myLast is not defined" + } + }, + { + "title": "returns the last n elements of the collection when the second optional argument (n) is provided", + "fullTitle": "index.js myLast returns the last n elements of the collection when the second optional argument (n) is provided", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myLast is not defined\n at Context. (test/indexTest.js:177:14)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myLast is not defined" + } + }, + { + "title": "retrieves all the names of the object's own enumerable properties", + "fullTitle": "index.js myKeys retrieves all the names of the object's own enumerable properties", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myKeys is not defined\n at Context. (test/indexTest.js:241:14)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myKeys is not defined" + } + }, + { + "title": "retrieves all the values of the object's own properties", + "fullTitle": "index.js myValues retrieves all the values of the object's own properties", + "duration": 0, + "currentRetry": 0, + "err": { + "stack": "ReferenceError: myValues is not defined\n at Context. (test/indexTest.js:254:14)\n at process.processImmediate (node:internal/timers:478:21)", + "message": "myValues is not defined" + } + } + ], + "passes": [ + { + "title": "calls alert with each element passed", + "fullTitle": "index.js myEach calls alert with each element passed", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "calls alert properly on object values", + "fullTitle": "index.js myEach calls alert properly on object values", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns the original collection", + "fullTitle": "index.js myEach returns the original collection", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "successfully returns a correctly populated array", + "fullTitle": "index.js myMap successfully returns a correctly populated array", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "does not modify the original array", + "fullTitle": "index.js myMap does not modify the original array", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "successfully returns a correctly populated array from modified object values", + "fullTitle": "index.js myMap successfully returns a correctly populated array from modified object values", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "does not modify the original object", + "fullTitle": "index.js myMap does not modify the original object", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "does not modify the original array", + "fullTitle": "index.js myReduce does not modify the original array", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "does not modify the original object", + "fullTitle": "index.js myReduce does not modify the original object", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "does not modify the original object", + "fullTitle": "index.js myKeys does not modify the original object", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "does not modify the original object", + "fullTitle": "index.js myValues does not modify the original object", + "duration": 0, + "currentRetry": 0, + "err": {} + } + ] +} \ No newline at end of file diff --git a/index.js b/index.js index e69de29bb..00035cb65 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,36 @@ +// COLLECTION FUNCTIONS (WORK WITH ARRAYS OR OBJECTS) +function ensureArray(collection) { + if (Array.isArray(collection)) { + return collection; + } else if (typeof collection === "object" && collection != null) { + return Object.values(collection); + } else { + return []; + } +} + +function myEach(collection, callback) { + const array = ensureArray(collection); + + for (const element of array) { + callback(element); + } + + return collection; +} + +function myMap(collection, callback) { + const array = ensureArray(collection); + const newArray = []; + + for (const element of array) { + newArray.push(callback(element)); + } + + return newArray; + +} + +// ARRAY FUNCTIONS + +// OBJECT FUNCTIONS From 2bc6450961b1362f7fe40e5f8f7a2ad8a0b683e7 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Thu, 22 May 2025 11:19:55 -0400 Subject: [PATCH 2/8] Reduce collection to a single value --- .results.json | 76 ++++++++++++++++++++------------------------------- index.js | 16 +++++++++++ 2 files changed, 45 insertions(+), 47 deletions(-) diff --git a/.results.json b/.results.json index 5d6fc9c49..95067df88 100644 --- a/.results.json +++ b/.results.json @@ -2,12 +2,12 @@ "stats": { "suites": 11, "tests": 27, - "passes": 11, + "passes": 14, "pending": 0, - "failures": 16, - "start": "2025-05-22T15:09:48.243Z", - "end": "2025-05-22T15:09:48.367Z", - "duration": 124 + "failures": 13, + "start": "2025-05-22T15:19:14.850Z", + "end": "2025-05-22T15:19:14.963Z", + "duration": 113 }, "tests": [ { @@ -64,20 +64,14 @@ "fullTitle": "index.js myReduce returns the correct reduced value when passed an initial value", "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: myReduce is not defined\n at Context. (test/indexTest.js:71:29)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myReduce is not defined" - } + "err": {} }, { "title": "returns the correct reduced value when not passed an initial value", "fullTitle": "index.js myReduce returns the correct reduced value when not passed an initial value", "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: myReduce is not defined\n at Context. (test/indexTest.js:76:29)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myReduce is not defined" - } + "err": {} }, { "title": "does not modify the original array", @@ -91,10 +85,7 @@ "fullTitle": "index.js myReduce returns the correct reduced value from object values", "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: myReduce is not defined\n at Context. (test/indexTest.js:85:25)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myReduce is not defined" - } + "err": {} }, { "title": "does not modify the original object", @@ -250,36 +241,6 @@ ], "pending": [], "failures": [ - { - "title": "returns the correct reduced value when passed an initial value", - "fullTitle": "index.js myReduce returns the correct reduced value when passed an initial value", - "duration": 0, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: myReduce is not defined\n at Context. (test/indexTest.js:71:29)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myReduce is not defined" - } - }, - { - "title": "returns the correct reduced value when not passed an initial value", - "fullTitle": "index.js myReduce returns the correct reduced value when not passed an initial value", - "duration": 0, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: myReduce is not defined\n at Context. (test/indexTest.js:76:29)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myReduce is not defined" - } - }, - { - "title": "returns the correct reduced value from object values", - "fullTitle": "index.js myReduce returns the correct reduced value from object values", - "duration": 0, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: myReduce is not defined\n at Context. (test/indexTest.js:85:25)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myReduce is not defined" - } - }, { "title": "returns the value if found", "fullTitle": "index.js myFind returns the value if found", @@ -461,6 +422,20 @@ "currentRetry": 0, "err": {} }, + { + "title": "returns the correct reduced value when passed an initial value", + "fullTitle": "index.js myReduce returns the correct reduced value when passed an initial value", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns the correct reduced value when not passed an initial value", + "fullTitle": "index.js myReduce returns the correct reduced value when not passed an initial value", + "duration": 0, + "currentRetry": 0, + "err": {} + }, { "title": "does not modify the original array", "fullTitle": "index.js myReduce does not modify the original array", @@ -468,6 +443,13 @@ "currentRetry": 0, "err": {} }, + { + "title": "returns the correct reduced value from object values", + "fullTitle": "index.js myReduce returns the correct reduced value from object values", + "duration": 0, + "currentRetry": 0, + "err": {} + }, { "title": "does not modify the original object", "fullTitle": "index.js myReduce does not modify the original object", diff --git a/index.js b/index.js index 00035cb65..9b433cb1c 100644 --- a/index.js +++ b/index.js @@ -31,6 +31,22 @@ function myMap(collection, callback) { } +function myReduce(collection, callback, acc) { + const array = ensureArray(collection); + let startIndex = 0; + + if (acc === undefined) { + acc = array[0]; + startIndex = 1; + } + + for (let i = startIndex; i < array.length; i++) { + acc = callback(acc, array[i], collection); + } + + return acc; +} + // ARRAY FUNCTIONS // OBJECT FUNCTIONS From 6320c8c7446b00d19a676fad964bb2ba7bc68d57 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Thu, 22 May 2025 11:30:27 -0400 Subject: [PATCH 3/8] Find element that fulfills a predicate function --- .results.json | 76 ++++++++++++++++++++------------------------------- index.js | 13 +++++++++ 2 files changed, 42 insertions(+), 47 deletions(-) diff --git a/.results.json b/.results.json index 95067df88..6f7bf0674 100644 --- a/.results.json +++ b/.results.json @@ -2,12 +2,12 @@ "stats": { "suites": 11, "tests": 27, - "passes": 14, + "passes": 17, "pending": 0, - "failures": 13, - "start": "2025-05-22T15:19:14.850Z", - "end": "2025-05-22T15:19:14.963Z", - "duration": 113 + "failures": 10, + "start": "2025-05-22T15:29:43.905Z", + "end": "2025-05-22T15:29:44.017Z", + "duration": 112 }, "tests": [ { @@ -99,30 +99,21 @@ "fullTitle": "index.js myFind returns the value if found", "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: myFind is not defined\n at Context. (test/indexTest.js:106:7)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myFind is not defined" - } + "err": {} }, { "title": "does not traverse the whole array if the value is found early", "fullTitle": "index.js myFind does not traverse the whole array if the value is found early", "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: myFind is not defined\n at Context. (test/indexTest.js:113:7)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myFind is not defined" - } + "err": {} }, { "title": "returns undefined if the value is not present", "fullTitle": "index.js myFind returns undefined if the value is not present", "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: myFind is not defined\n at Context. (test/indexTest.js:118:7)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myFind is not defined" - } + "err": {} }, { "title": "correctly filters for values that the callback evaluates as true", @@ -241,36 +232,6 @@ ], "pending": [], "failures": [ - { - "title": "returns the value if found", - "fullTitle": "index.js myFind returns the value if found", - "duration": 0, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: myFind is not defined\n at Context. (test/indexTest.js:106:7)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myFind is not defined" - } - }, - { - "title": "does not traverse the whole array if the value is found early", - "fullTitle": "index.js myFind does not traverse the whole array if the value is found early", - "duration": 0, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: myFind is not defined\n at Context. (test/indexTest.js:113:7)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myFind is not defined" - } - }, - { - "title": "returns undefined if the value is not present", - "fullTitle": "index.js myFind returns undefined if the value is not present", - "duration": 0, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: myFind is not defined\n at Context. (test/indexTest.js:118:7)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myFind is not defined" - } - }, { "title": "correctly filters for values that the callback evaluates as true", "fullTitle": "index.js myFilter correctly filters for values that the callback evaluates as true", @@ -457,6 +418,27 @@ "currentRetry": 0, "err": {} }, + { + "title": "returns the value if found", + "fullTitle": "index.js myFind returns the value if found", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "does not traverse the whole array if the value is found early", + "fullTitle": "index.js myFind does not traverse the whole array if the value is found early", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns undefined if the value is not present", + "fullTitle": "index.js myFind returns undefined if the value is not present", + "duration": 0, + "currentRetry": 0, + "err": {} + }, { "title": "does not modify the original object", "fullTitle": "index.js myKeys does not modify the original object", diff --git a/index.js b/index.js index 9b433cb1c..f787694ab 100644 --- a/index.js +++ b/index.js @@ -47,6 +47,19 @@ function myReduce(collection, callback, acc) { return acc; } +function myFind(collection, predicate) { + const array = ensureArray(collection); + let returnValue = undefined; + + for (let i = 0; i < array.length; i++) { + if (predicate(array[i]) === true) { + returnValue = array[i]; + break; + } + } + return returnValue; +} + // ARRAY FUNCTIONS // OBJECT FUNCTIONS From 83a08a8841f49138a94663acea75b43c4894885b Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Thu, 22 May 2025 11:43:37 -0400 Subject: [PATCH 4/8] Filter elements that fulfill a predicate function --- .results.json | 58 ++++++++++++++++++++------------------------------- index.js | 13 ++++++++++++ 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/.results.json b/.results.json index 6f7bf0674..e7e27be19 100644 --- a/.results.json +++ b/.results.json @@ -2,12 +2,12 @@ "stats": { "suites": 11, "tests": 27, - "passes": 17, + "passes": 19, "pending": 0, - "failures": 10, - "start": "2025-05-22T15:29:43.905Z", - "end": "2025-05-22T15:29:44.017Z", - "duration": 112 + "failures": 8, + "start": "2025-05-22T15:43:08.431Z", + "end": "2025-05-22T15:43:08.616Z", + "duration": 185 }, "tests": [ { @@ -69,7 +69,7 @@ { "title": "returns the correct reduced value when not passed an initial value", "fullTitle": "index.js myReduce returns the correct reduced value when not passed an initial value", - "duration": 0, + "duration": 1, "currentRetry": 0, "err": {} }, @@ -120,20 +120,14 @@ "fullTitle": "index.js myFilter correctly filters for values that the callback evaluates as true", "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: myFilter is not defined\n at Context. (test/indexTest.js:134:29)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myFilter is not defined" - } + "err": {} }, { "title": "correctly returns an empty array if no matching values are found", "fullTitle": "index.js myFilter correctly returns an empty array if no matching values are found", "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: myFilter is not defined\n at Context. (test/indexTest.js:139:29)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myFilter is not defined" - } + "err": {} }, { "title": "correctly returns the size of the collection when an array is passed", @@ -232,26 +226,6 @@ ], "pending": [], "failures": [ - { - "title": "correctly filters for values that the callback evaluates as true", - "fullTitle": "index.js myFilter correctly filters for values that the callback evaluates as true", - "duration": 0, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: myFilter is not defined\n at Context. (test/indexTest.js:134:29)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myFilter is not defined" - } - }, - { - "title": "correctly returns an empty array if no matching values are found", - "fullTitle": "index.js myFilter correctly returns an empty array if no matching values are found", - "duration": 0, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: myFilter is not defined\n at Context. (test/indexTest.js:139:29)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myFilter is not defined" - } - }, { "title": "correctly returns the size of the collection when an array is passed", "fullTitle": "index.js mySize correctly returns the size of the collection when an array is passed", @@ -393,7 +367,7 @@ { "title": "returns the correct reduced value when not passed an initial value", "fullTitle": "index.js myReduce returns the correct reduced value when not passed an initial value", - "duration": 0, + "duration": 1, "currentRetry": 0, "err": {} }, @@ -439,6 +413,20 @@ "currentRetry": 0, "err": {} }, + { + "title": "correctly filters for values that the callback evaluates as true", + "fullTitle": "index.js myFilter correctly filters for values that the callback evaluates as true", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "correctly returns an empty array if no matching values are found", + "fullTitle": "index.js myFilter correctly returns an empty array if no matching values are found", + "duration": 0, + "currentRetry": 0, + "err": {} + }, { "title": "does not modify the original object", "fullTitle": "index.js myKeys does not modify the original object", diff --git a/index.js b/index.js index f787694ab..e9bcf437e 100644 --- a/index.js +++ b/index.js @@ -60,6 +60,19 @@ function myFind(collection, predicate) { return returnValue; } +function myFilter(collection, predicate) { + const array = ensureArray(collection); + const trueValues = []; + + for (const value of array) { + if (predicate(value) === true) { + trueValues.push(value); + } + } + + return trueValues; +} + // ARRAY FUNCTIONS // OBJECT FUNCTIONS From 69604f83ed6dd78b9fcff964e067a9ebe796da0c Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Thu, 22 May 2025 11:47:10 -0400 Subject: [PATCH 5/8] Count number of values in collection --- .results.json | 58 ++++++++++++++++++++------------------------------- index.js | 11 ++++++++++ 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/.results.json b/.results.json index e7e27be19..929058c77 100644 --- a/.results.json +++ b/.results.json @@ -2,12 +2,12 @@ "stats": { "suites": 11, "tests": 27, - "passes": 19, + "passes": 21, "pending": 0, - "failures": 8, - "start": "2025-05-22T15:43:08.431Z", - "end": "2025-05-22T15:43:08.616Z", - "duration": 185 + "failures": 6, + "start": "2025-05-22T15:46:52.740Z", + "end": "2025-05-22T15:46:52.919Z", + "duration": 179 }, "tests": [ { @@ -69,7 +69,7 @@ { "title": "returns the correct reduced value when not passed an initial value", "fullTitle": "index.js myReduce returns the correct reduced value when not passed an initial value", - "duration": 1, + "duration": 0, "currentRetry": 0, "err": {} }, @@ -134,20 +134,14 @@ "fullTitle": "index.js mySize correctly returns the size of the collection when an array is passed", "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: mySize is not defined\n at Context. (test/indexTest.js:149:7)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "mySize is not defined" - } + "err": {} }, { "title": "correctly returns the size of the collection (amount of keys) when an object is passed", "fullTitle": "index.js mySize correctly returns the size of the collection (amount of keys) when an object is passed", "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: mySize is not defined\n at Context. (test/indexTest.js:153:7)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "mySize is not defined" - } + "err": {} }, { "title": "returns the first element of the collection", @@ -226,26 +220,6 @@ ], "pending": [], "failures": [ - { - "title": "correctly returns the size of the collection when an array is passed", - "fullTitle": "index.js mySize correctly returns the size of the collection when an array is passed", - "duration": 0, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: mySize is not defined\n at Context. (test/indexTest.js:149:7)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "mySize is not defined" - } - }, - { - "title": "correctly returns the size of the collection (amount of keys) when an object is passed", - "fullTitle": "index.js mySize correctly returns the size of the collection (amount of keys) when an object is passed", - "duration": 0, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: mySize is not defined\n at Context. (test/indexTest.js:153:7)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "mySize is not defined" - } - }, { "title": "returns the first element of the collection", "fullTitle": "index.js myFirst returns the first element of the collection", @@ -367,7 +341,7 @@ { "title": "returns the correct reduced value when not passed an initial value", "fullTitle": "index.js myReduce returns the correct reduced value when not passed an initial value", - "duration": 1, + "duration": 0, "currentRetry": 0, "err": {} }, @@ -427,6 +401,20 @@ "currentRetry": 0, "err": {} }, + { + "title": "correctly returns the size of the collection when an array is passed", + "fullTitle": "index.js mySize correctly returns the size of the collection when an array is passed", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "correctly returns the size of the collection (amount of keys) when an object is passed", + "fullTitle": "index.js mySize correctly returns the size of the collection (amount of keys) when an object is passed", + "duration": 0, + "currentRetry": 0, + "err": {} + }, { "title": "does not modify the original object", "fullTitle": "index.js myKeys does not modify the original object", diff --git a/index.js b/index.js index e9bcf437e..fa0dcc7dd 100644 --- a/index.js +++ b/index.js @@ -73,6 +73,17 @@ function myFilter(collection, predicate) { return trueValues; } +function mySize(collection) { + const array = ensureArray(collection); + let count = 0; + + for (let i = 0; i < array.length; i++) { + count++; + } + + return count; +} + // ARRAY FUNCTIONS // OBJECT FUNCTIONS From 350a68a411ef2a8be33a60f667fd9f3e0b33a9a1 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Thu, 22 May 2025 11:57:35 -0400 Subject: [PATCH 6/8] Return first n elements of an array --- .results.json | 62 +++++++++++++++++++++------------------------------ index.js | 11 +++++++++ 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/.results.json b/.results.json index 929058c77..44f0f9c6e 100644 --- a/.results.json +++ b/.results.json @@ -2,12 +2,12 @@ "stats": { "suites": 11, "tests": 27, - "passes": 21, + "passes": 23, "pending": 0, - "failures": 6, - "start": "2025-05-22T15:46:52.740Z", - "end": "2025-05-22T15:46:52.919Z", - "duration": 179 + "failures": 4, + "start": "2025-05-22T15:57:17.020Z", + "end": "2025-05-22T15:57:17.155Z", + "duration": 135 }, "tests": [ { @@ -20,7 +20,7 @@ { "title": "calls alert properly on object values", "fullTitle": "index.js myEach calls alert properly on object values", - "duration": 0, + "duration": 1, "currentRetry": 0, "err": {} }, @@ -148,25 +148,19 @@ "fullTitle": "index.js myFirst returns the first element of the collection", "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: myFirst is not defined\n at Context. (test/indexTest.js:161:7)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myFirst is not defined" - } + "err": {} }, { "title": "returns the first n elements of the collection when the second optional argument (n) is provided", "fullTitle": "index.js myFirst returns the first n elements of the collection when the second optional argument (n) is provided", "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: myFirst is not defined\n at Context. (test/indexTest.js:165:14)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myFirst is not defined" - } + "err": {} }, { "title": "returns the last element of the collection", "fullTitle": "index.js myLast returns the last element of the collection", - "duration": 0, + "duration": 1, "currentRetry": 0, "err": { "stack": "ReferenceError: myLast is not defined\n at Context. (test/indexTest.js:173:7)\n at process.processImmediate (node:internal/timers:478:21)", @@ -220,30 +214,10 @@ ], "pending": [], "failures": [ - { - "title": "returns the first element of the collection", - "fullTitle": "index.js myFirst returns the first element of the collection", - "duration": 0, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: myFirst is not defined\n at Context. (test/indexTest.js:161:7)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myFirst is not defined" - } - }, - { - "title": "returns the first n elements of the collection when the second optional argument (n) is provided", - "fullTitle": "index.js myFirst returns the first n elements of the collection when the second optional argument (n) is provided", - "duration": 0, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: myFirst is not defined\n at Context. (test/indexTest.js:165:14)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myFirst is not defined" - } - }, { "title": "returns the last element of the collection", "fullTitle": "index.js myLast returns the last element of the collection", - "duration": 0, + "duration": 1, "currentRetry": 0, "err": { "stack": "ReferenceError: myLast is not defined\n at Context. (test/indexTest.js:173:7)\n at process.processImmediate (node:internal/timers:478:21)", @@ -292,7 +266,7 @@ { "title": "calls alert properly on object values", "fullTitle": "index.js myEach calls alert properly on object values", - "duration": 0, + "duration": 1, "currentRetry": 0, "err": {} }, @@ -415,6 +389,20 @@ "currentRetry": 0, "err": {} }, + { + "title": "returns the first element of the collection", + "fullTitle": "index.js myFirst returns the first element of the collection", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns the first n elements of the collection when the second optional argument (n) is provided", + "fullTitle": "index.js myFirst returns the first n elements of the collection when the second optional argument (n) is provided", + "duration": 0, + "currentRetry": 0, + "err": {} + }, { "title": "does not modify the original object", "fullTitle": "index.js myKeys does not modify the original object", diff --git a/index.js b/index.js index fa0dcc7dd..55bcc9bc3 100644 --- a/index.js +++ b/index.js @@ -85,5 +85,16 @@ function mySize(collection) { } // ARRAY FUNCTIONS +function myFirst(array, n) { + if (n === undefined) { + return array[0]; + } else { + const slice = []; + for (let i = 0; i < n; i++) { + slice.push(array[i]) + } + return slice; + } +} // OBJECT FUNCTIONS From 1205a93762092bbcdbe1872037b29defb1f9b027 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Thu, 22 May 2025 12:02:53 -0400 Subject: [PATCH 7/8] Return last n elements of an array --- .results.json | 64 +++++++++++++++++++++------------------------------ index.js | 12 ++++++++++ 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/.results.json b/.results.json index 44f0f9c6e..264fe32f7 100644 --- a/.results.json +++ b/.results.json @@ -2,18 +2,18 @@ "stats": { "suites": 11, "tests": 27, - "passes": 23, + "passes": 25, "pending": 0, - "failures": 4, - "start": "2025-05-22T15:57:17.020Z", - "end": "2025-05-22T15:57:17.155Z", - "duration": 135 + "failures": 2, + "start": "2025-05-22T16:02:33.265Z", + "end": "2025-05-22T16:02:33.445Z", + "duration": 180 }, "tests": [ { "title": "calls alert with each element passed", "fullTitle": "index.js myEach calls alert with each element passed", - "duration": 0, + "duration": 1, "currentRetry": 0, "err": {} }, @@ -62,7 +62,7 @@ { "title": "returns the correct reduced value when passed an initial value", "fullTitle": "index.js myReduce returns the correct reduced value when passed an initial value", - "duration": 0, + "duration": 1, "currentRetry": 0, "err": {} }, @@ -160,22 +160,16 @@ { "title": "returns the last element of the collection", "fullTitle": "index.js myLast returns the last element of the collection", - "duration": 1, + "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: myLast is not defined\n at Context. (test/indexTest.js:173:7)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myLast is not defined" - } + "err": {} }, { "title": "returns the last n elements of the collection when the second optional argument (n) is provided", "fullTitle": "index.js myLast returns the last n elements of the collection when the second optional argument (n) is provided", "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: myLast is not defined\n at Context. (test/indexTest.js:177:14)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myLast is not defined" - } + "err": {} }, { "title": "retrieves all the names of the object's own enumerable properties", @@ -214,26 +208,6 @@ ], "pending": [], "failures": [ - { - "title": "returns the last element of the collection", - "fullTitle": "index.js myLast returns the last element of the collection", - "duration": 1, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: myLast is not defined\n at Context. (test/indexTest.js:173:7)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myLast is not defined" - } - }, - { - "title": "returns the last n elements of the collection when the second optional argument (n) is provided", - "fullTitle": "index.js myLast returns the last n elements of the collection when the second optional argument (n) is provided", - "duration": 0, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: myLast is not defined\n at Context. (test/indexTest.js:177:14)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myLast is not defined" - } - }, { "title": "retrieves all the names of the object's own enumerable properties", "fullTitle": "index.js myKeys retrieves all the names of the object's own enumerable properties", @@ -259,7 +233,7 @@ { "title": "calls alert with each element passed", "fullTitle": "index.js myEach calls alert with each element passed", - "duration": 0, + "duration": 1, "currentRetry": 0, "err": {} }, @@ -308,7 +282,7 @@ { "title": "returns the correct reduced value when passed an initial value", "fullTitle": "index.js myReduce returns the correct reduced value when passed an initial value", - "duration": 0, + "duration": 1, "currentRetry": 0, "err": {} }, @@ -403,6 +377,20 @@ "currentRetry": 0, "err": {} }, + { + "title": "returns the last element of the collection", + "fullTitle": "index.js myLast returns the last element of the collection", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns the last n elements of the collection when the second optional argument (n) is provided", + "fullTitle": "index.js myLast returns the last n elements of the collection when the second optional argument (n) is provided", + "duration": 0, + "currentRetry": 0, + "err": {} + }, { "title": "does not modify the original object", "fullTitle": "index.js myKeys does not modify the original object", diff --git a/index.js b/index.js index 55bcc9bc3..5f3b1cf8c 100644 --- a/index.js +++ b/index.js @@ -97,4 +97,16 @@ function myFirst(array, n) { } } +function myLast(array, n) { + if (n === undefined) { + return array[array.length - 1]; + } else { + const slice = []; + for (let i = array.length - n; i < array.length; i++) { + slice.push(array[i]); + } + return slice; + } +} + // OBJECT FUNCTIONS From 4429a465413dac6fb1e132980857df8df1dee8f2 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Thu, 22 May 2025 12:27:32 -0400 Subject: [PATCH 8/8] Return keys and values in arrays --- .results.json | 65 +++++++++++++++++++++------------------------------ index.js | 18 ++++++++++++++ 2 files changed, 44 insertions(+), 39 deletions(-) diff --git a/.results.json b/.results.json index 264fe32f7..1912d96ba 100644 --- a/.results.json +++ b/.results.json @@ -2,18 +2,18 @@ "stats": { "suites": 11, "tests": 27, - "passes": 25, + "passes": 27, "pending": 0, - "failures": 2, - "start": "2025-05-22T16:02:33.265Z", - "end": "2025-05-22T16:02:33.445Z", - "duration": 180 + "failures": 0, + "start": "2025-05-22T16:27:13.512Z", + "end": "2025-05-22T16:27:13.626Z", + "duration": 114 }, "tests": [ { "title": "calls alert with each element passed", "fullTitle": "index.js myEach calls alert with each element passed", - "duration": 1, + "duration": 0, "currentRetry": 0, "err": {} }, @@ -62,7 +62,7 @@ { "title": "returns the correct reduced value when passed an initial value", "fullTitle": "index.js myReduce returns the correct reduced value when passed an initial value", - "duration": 1, + "duration": 0, "currentRetry": 0, "err": {} }, @@ -176,10 +176,7 @@ "fullTitle": "index.js myKeys retrieves all the names of the object's own enumerable properties", "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: myKeys is not defined\n at Context. (test/indexTest.js:241:14)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myKeys is not defined" - } + "err": {} }, { "title": "does not modify the original object", @@ -193,10 +190,7 @@ "fullTitle": "index.js myValues retrieves all the values of the object's own properties", "duration": 0, "currentRetry": 0, - "err": { - "stack": "ReferenceError: myValues is not defined\n at Context. (test/indexTest.js:254:14)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myValues is not defined" - } + "err": {} }, { "title": "does not modify the original object", @@ -207,33 +201,12 @@ } ], "pending": [], - "failures": [ - { - "title": "retrieves all the names of the object's own enumerable properties", - "fullTitle": "index.js myKeys retrieves all the names of the object's own enumerable properties", - "duration": 0, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: myKeys is not defined\n at Context. (test/indexTest.js:241:14)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myKeys is not defined" - } - }, - { - "title": "retrieves all the values of the object's own properties", - "fullTitle": "index.js myValues retrieves all the values of the object's own properties", - "duration": 0, - "currentRetry": 0, - "err": { - "stack": "ReferenceError: myValues is not defined\n at Context. (test/indexTest.js:254:14)\n at process.processImmediate (node:internal/timers:478:21)", - "message": "myValues is not defined" - } - } - ], + "failures": [], "passes": [ { "title": "calls alert with each element passed", "fullTitle": "index.js myEach calls alert with each element passed", - "duration": 1, + "duration": 0, "currentRetry": 0, "err": {} }, @@ -282,7 +255,7 @@ { "title": "returns the correct reduced value when passed an initial value", "fullTitle": "index.js myReduce returns the correct reduced value when passed an initial value", - "duration": 1, + "duration": 0, "currentRetry": 0, "err": {} }, @@ -391,6 +364,13 @@ "currentRetry": 0, "err": {} }, + { + "title": "retrieves all the names of the object's own enumerable properties", + "fullTitle": "index.js myKeys retrieves all the names of the object's own enumerable properties", + "duration": 0, + "currentRetry": 0, + "err": {} + }, { "title": "does not modify the original object", "fullTitle": "index.js myKeys does not modify the original object", @@ -398,6 +378,13 @@ "currentRetry": 0, "err": {} }, + { + "title": "retrieves all the values of the object's own properties", + "fullTitle": "index.js myValues retrieves all the values of the object's own properties", + "duration": 0, + "currentRetry": 0, + "err": {} + }, { "title": "does not modify the original object", "fullTitle": "index.js myValues does not modify the original object", diff --git a/index.js b/index.js index 5f3b1cf8c..cf161c11b 100644 --- a/index.js +++ b/index.js @@ -110,3 +110,21 @@ function myLast(array, n) { } // OBJECT FUNCTIONS +function myKeys(object) { + const keys = []; + + for (const key in object) { + keys.push(key); + } + return keys; +} + +function myValues(object) { + const values = []; + + for (const value in object) { + values.push(object[value]); + } + + return values; +}