Skip to content

Instantly share code, notes, and snippets.

@kolya182
Last active June 1, 2017 04:05
Show Gist options
  • Save kolya182/e711516dde274ed1d208279851ec008b to your computer and use it in GitHub Desktop.
Save kolya182/e711516dde274ed1d208279851ec008b to your computer and use it in GitHub Desktop.
Mykola Radchenko
function billTotal(subtotal) {
let tax = subtotal * 0.15;
let tip = subtotal * 0.095;
return subtotal + tax + tip;
}
function range(start, end) {
let resultArr = [];
if (start > end || start === end) {
return [];
}
while(start < end) {
resultArr.push(start);
start++
}
return resultArr;
}
range(0, 4);
function getFullName(obj) {
let firstName = obj.name.first;
let middleName = obj.name.middle;
let lastName = obj.name.last;
if (typeof middleName === 'string') {
return `${firstName} ${middleName} ${lastName}`;
} else {
return `${firstName} ${lastName}`;
}
}
let person = {
name : {
first : "Alyssa",
middle: "P.",
last: "Hacker"
},
age : 26
}
var personB = {
name: {
first: "Ben",
last: "Bitdiddle"
},
age: 34
}
getFullName(person);
getFullName(personB);
var people = [
{name: {first: "Alyssa", middle: "P.", last: "Hacker"}, age: 26},
{name: {first: "Ben", last: "Bitdiddle"}, age: 34},
{name: {first: "Eva", middle: "Lu", last: "Ator"}, age: 40},
{name: {first: "Lem", middle: "E.", last: "Tweakit"}, age: 45},
{name: {first: "Louis", last: "Reasoner"}, age: 21}
];
function longestName(people) {
let longestName = {};
let longestPesonName = 0;
people.forEach(person => {
let nameLength = getFullName(person).length;
if(nameLength > longestPesonName) {
longestPesonName = nameLength;
longestName = person;
}
});
return longestName;
}
longestName(people);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment