Ad
Code
Diff
  • 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;
Code
Diff
  • 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];
Code
Diff
  • var middleCharacter = (str) => str.slice(str.length/2 - !(str.length % 2), str.length/2+1);
    • function middleCharacter(str) {
    • return str.slice(str.length/2 - !(str.length % 2), str.length/2+1);
    • };
    • var middleCharacter = (str) => str.slice(str.length/2 - !(str.length % 2), str.length/2+1);
Fundamentals
Arrays
Data Types
Code
Diff
  • 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];
Code
Diff
  • 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);
    • };
Code
Diff
  • function numSum(num){
      return (num * (num + 1)) / 2;
    }
    • function numSum(num){
    • var sum = 0;
    • for (var i = 1; i <= num; i++) {
    • sum += i
    • }
    • return sum
    • return (num * (num + 1)) / 2;
    • }