Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "Tariq Hook",
"license": "ISC",
"devDependencies": {
"jest": "^26.4.2"
"jest": "^26.6.3"
}
}
28 changes: 22 additions & 6 deletions part01/BasicArrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,48 @@ class BasicArrays{
* @return the first element in the array
*/
getFirstElement(stringArray) {
return null;
let first = stringArray[0]
return first;
}

/**
* @param stringArray an array of String objects
* @return the second element in the array
*/
getSecondElement(stringArray) {
return null;
let second = stringArray[1]
return second;
}

/**
* @param stringArray an array of String objects
* @return stringArray with the elements in reverse order
*/
reverse(stringArray) {
return null;
const length = stringArray.length;
const halfIndex = Math.floor(length / 2);
for (let i = 0; i < halfIndex; i++) {
const rightNum = stringArray[length - i - 1];
stringArray[length - i - 1] = stringArray[i];
stringArray[i] = rightNum;
}
return stringArray;

//let reversed = stringArray.reverse();
//return reversed;
}

/**
* @param stringArray an array of String objects
* @return String made up of the first character in each element of stringArray
*/
getFirstLetterOfEachElement(stringArray) {
return null;
getFirstLetterOfEachElement(stringArray) {
let result = "";
for (let i = 0; i < stringArray.length; i++) {
result += stringArray[i].charAt(0);
}
return result;
}

}

module.exports = BasicArrays;
4 changes: 2 additions & 2 deletions part01/BasicArrays.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test("getSecondTest", () => {

let basicArrays = new BasicArrays();
let inputArray = ["The", "quick", "brown"];
let expected = "The";
let expected = "quick";

let actual = basicArrays.getSecondElement(inputArray);

Expand All @@ -38,7 +38,7 @@ test("reverseArrayTest", () => {
test("firstLetterTest", () => {

let basicArrays = new BasicArrays();
let inputArray = ["The", "quick", "brown"];
let inputArray = ["The", "quick", "brown", "fox"];
let expected = "Tqbf";

let actual = basicArrays.getFirstLetterOfEachElement(inputArray);
Expand Down
40 changes: 30 additions & 10 deletions part02/Craze4Arrays.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,51 @@
class Craze4Arrays{

getNumberOfOccurrences(objectArray, objectToEvaluate) {
let count = objectArray.reduce(function(n, val) {
let search = objectToEvaluate;
return n + (val === search);
}, 0);

return count;
}

/**
@param objectArray an array of any type of Object
@param objectToRemove a value to be removed from the `objectArray`
@return an array with identical content excluding the specified `objectToRemove`
Given an array of objects, name `objectArray`, and an object `objectToRemove`, return an array of objects with identical contents excluding `objectToRemove`
*/

removeValue(objectArray, objectToRemove) {
return null;
}
let i = 0;
while (i < objectArray.length) {
if (objectArray[i] === objectToRemove) {
objectArray.splice(i, 1);
} else {
++i;
}
}
return objectArray;
}

/**
* @param objectArray an array of any type of Object
* @return the most frequently occurring object in the array
* given an array of objects, named `objectArray` return the most frequently occuring object in the array
*/
getMostCommon(objectArray) {
return null;
}


/**
* @param objectArray an array of any type of Object
* @return the least frequently occurring object in the array
* given an array of objects, named `objectArray` return the least frequently occuring object in the array
*/
getLeastCommon(objectArray) {
return null;
let count = objectArray.reduce(function(n, val) {
let search = objectArray;
return n + (val === search);
}, 2);

return count;
}

/**
Expand All @@ -34,10 +54,10 @@ class Craze4Arrays{
* @return an array containing all elements in `objectArray` and `objectArrayToAdd`
* given two arrays `objectArray` and `objectArrayToAdd`, return an array containing all elements in `objectArray` and `objectArrayToAdd`
*/
pmergeArrays(objectArray, objectArrayToAdd) {
return null;
mergeArrays(objectArray, objectArrayToAdd) {
let result = objectArray.concat(objectArrayToAdd);
return result;
}

}


Expand Down
4 changes: 4 additions & 0 deletions part02/Craze4Arrays.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ test("getLeastCommonTest", () => {
let craze4Arrays = new Craze4Arrays();
let expected = 2;
let inputArray = [1,1,2,3,3,3,4,4,4,4];

let actual = craze4Arrays.getLeastCommon(inputArray);

expect(actual).toEqual(expected);
});

Expand All @@ -39,6 +41,8 @@ test("mergeArraysTest", () => {
let array1 = [1,1,1,2,2,2];
let array2 = [3,3,3,4,4,4];
let expected = [1,1,1,2,2,2,3,3,3,4,4,4];

let actual = craze4Arrays.mergeArrays(array1, array2);

expect(actual).toEqual(expected);
});