var getAge = (today, dob) => (today && dob) ? (new Date(today)).getYear() - new Date(dob).getYear() : null;
var getAge = function(today, dob) {if(!today || !dob) {return null;}var now = new Date(today);return now.getYear() - new Date(dob).getYear();};- var getAge = (today, dob) => (today && dob) ? (new Date(today)).getYear() - new Date(dob).getYear() : null;
var longestString = (str) => str.split(' ').sort((a, b) => b.length - a.length)[0];
function longestString(str){return str.split(' ').sort(function(a,b) {return b.length - a.length})[0]}- var longestString = (str) => str.split(' ').sort((a, b) => b.length - a.length)[0];
describe("Solution", function(){ it("did you find the longest?", function(){ Test.assertEquals(longestString('I went running around the park'), "running", "try again"); Test.assertEquals(longestString('There were a lot of barking dogs everywhere'), "everywhere", "try again"); Test.assertEquals(longestString('now for some reason my shoe smells funny'), "reason", "try again"); }); });
- describe("Solution", function(){
- it("did you find the longest?", function(){
- Test.assertEquals(longestString('I went running around the park'), "running", "try again");
- Test.assertEquals(longestString('There were a lot of barking dogs everywhere'), "everywhere", "try again");
- Test.assertEquals(longestString('now for some reason my shoe smells funny'), "reason", "try again");
- });
- });
Fundamentals
Arrays
Data Types
var thirdGreatest = (arr) => arr.sort((a,b) => a - b)[arr.length - 3];
function thirdGreatest(arr){return arr.sort( (a,b) => a - b)[arr.length-3]}- var thirdGreatest = (arr) => arr.sort((a,b) => a - b)[arr.length - 3];
describe("Solution", function(){ it("did you return the correct number?", function(){ Test.assertEquals(thirdGreatest([4,8,1,5,3]), 4, "Better try again"); Test.assertEquals(thirdGreatest([45,38,1,0,89,6,77]), 45, "Better try again"); Test.assertEquals(thirdGreatest([878,1,1,0,46,123]), 46, "Better try again"); Test.assertEquals(thirdGreatest([8,99,0]), 0, "Better try again"); Test.assertEquals(thirdGreatest([1,1,2,3,3,4]), 3, "Better try again"); Test.assertEquals(thirdGreatest([79831,436,683,3645,2399,0,0,66]), 2399, "Better try again"); Test.assertEquals(thirdGreatest([6,33,7,41,3,388]), 33, "Better try again"); }); });
- describe("Solution", function(){
- it("did you return the correct number?", function(){
- Test.assertEquals(thirdGreatest([4,8,1,5,3]), 4, "Better try again");
- Test.assertEquals(thirdGreatest([45,38,1,0,89,6,77]), 45, "Better try again");
- Test.assertEquals(thirdGreatest([878,1,1,0,46,123]), 46, "Better try again");
- Test.assertEquals(thirdGreatest([8,99,0]), 0, "Better try again");
- Test.assertEquals(thirdGreatest([1,1,2,3,3,4]), 3, "Better try again");
- Test.assertEquals(thirdGreatest([79831,436,683,3645,2399,0,0,66]), 2399, "Better try again");
- Test.assertEquals(thirdGreatest([6,33,7,41,3,388]), 33, "Better try again");
- });
- });
function middleCharacter(str) { return str.slice(str.length/2 - !(str.length % 2), str.length/2+1); };
- function middleCharacter(str) {
if (str.length % 2 !== 0) {return str.slice(str.length/2, str.length/2+1);};return str.slice(str.length/2-1, str.length/2+1);- return str.slice(str.length/2 - !(str.length % 2), str.length/2+1);
- };