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
22 changes: 14 additions & 8 deletions src/arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
*/

function isArrayLengthOdd(numbers: number[]): boolean {
// Your code here

return false; // replace false with what you see is fit
if (numbers.length % 2 !== 0) {
return true;
} else {
return false;
}
}

/**
Expand All @@ -27,7 +29,11 @@ function isArrayLengthOdd(numbers: number[]): boolean {
*/

function isArrayLengthEven(numbers: number[]): boolean {
// Your code here
if (numbers.length % 2 == 0) {
return true;
} else {
return false;
}

return false; // replace false with what you see is fit
}
Expand All @@ -42,8 +48,8 @@ function isArrayLengthEven(numbers: number[]): boolean {
*/
function addLailaToArray(instructors: string[]): string[] {
// Your code here

return []; // replace empty array with what you see is fit
instructors.push("Laila");
return instructors; // replace empty array with what you see is fit
}

/**
Expand All @@ -54,10 +60,10 @@ function addLailaToArray(instructors: string[]): string[] {
* e.g.
* eliminateTeam(["Brazil", "Germany", "Italy"]); // => "Italy"
*/
function eliminateTeam(teams: string[]): string {
function eliminateTeam(teams: string[]): string | undefined {
// Your code here

return ""; // replace empty string with what you see is fit
return teams.pop(); // replace empty string with what you see is fit
}

export { isArrayLengthOdd, isArrayLengthEven, addLailaToArray, eliminateTeam };
19 changes: 14 additions & 5 deletions src/challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
* explanation: the number of elements provided is 5. 5 is odd, so we return empty array
*/
function secondHalfOfArrayIfItIsEven(fruits: string[]): string[] {
// Your code here

return []; // replace empty array with what you see is fit
if (fruits.length % 2 == 0) {
fruits.splice(0, fruits.length - fruits.length / 2);
return fruits;
} else {
return [];
}
}

/**
Expand All @@ -33,9 +36,15 @@ function secondHalfOfArrayIfItIsEven(fruits: string[]): string[] {
* - Use string method .slice()
*/
function youGottaCalmDown(shout: string): string {
// Your code here
if (shout.includes("!")) {
let indexOfExclimation: number = shout.indexOf("!");

return shout.slice(0, indexOfExclimation + 1);
} else {
return shout;
}

return ""; // replace the empty string with what you see is fit
// replace the empty string with what you see is fit
}

export { secondHalfOfArrayIfItIsEven, youGottaCalmDown };