Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions assessment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


// 1. Write a function called helloWorld that returns the string 'Hello World!'.
const helloWorld = () => 'Hello World'

// 2. Write a function called lambdaSchool that has a single parameter called num.
// num will be a positive integer.
Expand All @@ -16,6 +17,13 @@
// lambdaSchool(15); // returns 'Lambda School'
// lambdaSchool(8); // returns 8

const lambdaSchool = num =>{
return num % 3 === 0 && num % 5 === 0 ? 'Lambda School' :
num % 3 === 0 ? 'Lambda' :
num % 5 === 0 ? 'School' :
num
}

// 3. Write a function called longestString that has a single parameter called strs.
// strs will be an array of strings.
// Return the longest string that is in strs.
Expand All @@ -25,6 +33,13 @@
// longestString(['hi', 'hello', 'ni hao', 'guten tag']); // returns 'guten tag'
// longestString(['JavaScript', 'HTML', 'CSS']); // returns 'JavaScript'

const longestString = strs =>{
return strs.reduce((longestString, currentString)=>{
if(longestString.length < currentString.length) longestString = currentString
return longestString
})
}

// 4. Write a function called computeUserAverageAge that has a single parameter called users
// users is an array of user objects.
// Each user object has a property called age that is a number.
Expand All @@ -44,6 +59,12 @@
// }];
// computeUserAverage(users); // returns 62 (This number is rounded up from 61.6666)

const computeUserAverageAge = users =>{
const answer = users.map(user=> user.age)
.reduce((sum, currAge)=> sum+=currAge) / users.length
return Math.round(answer)
}


module.exports = {
// helloWorld,
Expand Down
Loading