Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark committed Jul 3, 2021
0 parents commit b6423b2
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
30 changes: 30 additions & 0 deletions find-findindex.js
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) {}
40 changes: 40 additions & 0 deletions find-findindex.test.js
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);

});
});
16 changes: 16 additions & 0 deletions index.html
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>

0 comments on commit b6423b2

Please sign in to comment.