-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mark
committed
Jul 3, 2021
0 parents
commit b6423b2
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Write a function called `findUserByUsername` which accepts an array of objects, each with a key of username, and a string. The function should return the first object with the key of username that matches the string passed to the function. If the object is not found, return undefined. | ||
const users = [ | ||
{username: 'mlewis'}, | ||
{username: 'akagen'}, | ||
{username: 'msmith'} | ||
]; | ||
findUserByUsername(users, 'mlewis') // {username: 'mlewis'} | ||
findUserByUsername(users, 'taco') // undefined | ||
*/ | ||
|
||
|
||
function findUserByUsername(usersArray, username) {} | ||
|
||
/* | ||
Write a function called `removeUser` which accepts an array of objects, each with a key of username, and a string. The function should remove the object from the array. If the object is not found, return undefined. | ||
const users = [ | ||
{username: 'mlewis'}, | ||
{username: 'akagen'}, | ||
{username: 'msmith'} | ||
]; | ||
removeUser(users, 'akagen') // {username: 'akagen'} | ||
removeUser(users, 'akagen') // undefined | ||
*/ | ||
|
||
function removeUser(usersArray, username) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
describe("#findUserByUsername", function() { | ||
let users; | ||
beforeEach(function() { | ||
users = [ | ||
{ username: "mlewis" }, | ||
{ username: "akagen" }, | ||
{ username: "msmith" } | ||
]; | ||
}); | ||
it("returns the object if the username matches the string passed", function() { | ||
expect(findUserByUsername(users, "akagen")).toEqual({ username: "akagen" }); | ||
}); | ||
it("returns undefined if a username is not found", function() { | ||
expect(findUserByUsername(users, 'taco')).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe("#removeUser", function() { | ||
let users; | ||
beforeEach(function(){ | ||
users = [ | ||
{ username: "mlewis" }, | ||
{ username: "akagen" }, | ||
{ username: "msmith" } | ||
]; | ||
}) | ||
it("removes a user from an array", function() { | ||
removeUser(users, "mlewis"); | ||
expect(users.length).toEqual(2) | ||
|
||
}); | ||
it("returns the removed user", function() { | ||
expect(removeUser(users,"mlewis")).toEqual({ username: "mlewis" }); | ||
}); | ||
it("returns undefined a user from an array", function() { | ||
expect(removeUser(users, "taco")).toEqual(undefined); | ||
expect(users.length).toEqual(3); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" dir="ltr"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title></title> | ||
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/jasmine.css"> | ||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/jasmine.js"></script> | ||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/jasmine-html.js"></script> | ||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/boot.js"></script> | ||
<script type="text/javascript" src="find-findindex.js"></script> | ||
<script type="text/javascript" src="find-findindex.test.js"></script> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> |