Skip to content

Instantly share code, notes, and snippets.

@stoneboyindc
Last active April 14, 2021 20:32
Show Gist options
  • Save stoneboyindc/f725a696c7c1ac4b8899d5b75dc01c80 to your computer and use it in GitHub Desktop.
Save stoneboyindc/f725a696c7c1ac4b8899d5b75dc01c80 to your computer and use it in GitHub Desktop.
const findStudentScoreByName = require("../src/solution");
const expect = require("chai").expect;
describe("Checking equality", () => {
it("should return a student score if the name matches", () => {
const students = [
{ name: "Leo Yeon-Joo", score: 8.9 },
{ name: "Morgan Sutton", score: 7.4 },
{ name: "Natalee Vargas", score: 9.2 },
];
const expected = students[0].score;
const existedStudent = "Leo Yeon-Joo";
const actual = findStudentScoreByName(students, existedStudent);
expect(expected).to.equal(actual);
});
it("should not return a student score if the name matches", () => {
const students = [
{ name: "Leo Yeon-Joo", score: 8.9 },
{ name: "Morgan Sutton", score: 7.4 },
{ name: "Natalee Vargas", score: 9.2 },
];
const nonExistedStudent = "Foo Bar";
const actual = findStudentScoreByName(students, nonExistedStudent);
expect(null).to.equal(actual);
});
});
@stoneboyindc
Copy link
Author

function findStudentScoreByName(students, name) {
  for (let i=0; i<students.length; i++){
    if(students[i].name===name){
      return students[i].score;
    }
  } 
  return null;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment