-
Notifications
You must be signed in to change notification settings - Fork 229
pierre-piot & darek-glowinski #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dglowinski
wants to merge
1
commit into
ironhack-labs:master
Choose a base branch
from
dglowinski:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
|
||
|
||
var opinions = [ "This is the best job ever", | ||
"Satisfied", | ||
"At least I get paid", | ||
"I'm looking for another job", | ||
"I don't want to answer"]; | ||
|
||
|
||
|
||
function select10Opinions(){ | ||
|
||
return _.times(10,function(){ | ||
return opinions[Math.floor(Math.random() * 5)]; | ||
}) | ||
|
||
} | ||
console.log(select10Opinions()); | ||
|
||
|
||
var employeeSatisfaction = []; | ||
function call5times(){ | ||
return _.times(5,select10Opinions); | ||
} | ||
|
||
employeeSatisfaction = call5times(); | ||
|
||
|
||
console.log(employeeSatisfaction); | ||
|
||
// Exercise 2 | ||
|
||
function nameBirthday(array) { | ||
return _.chunk(array, 2); | ||
} | ||
|
||
var orderedBday = nameBirthday(birthdays) | ||
console.log(orderedBday); | ||
|
||
|
||
var moreBirthdays = ["Lily Evans", "30 January", "James Potter", "27 March", | ||
"Dudley Dursley", "30 June", "Tom Riddle", "31 December"]; | ||
|
||
function concatBday (a , b){ | ||
return _.concat(a, b); | ||
} | ||
|
||
|
||
var nameBirthday2 = nameBirthday(moreBirthdays) | ||
|
||
var finalBday = concatBday(orderedBday, nameBirthday2); | ||
console.log(finalBday); | ||
|
||
|
||
|
||
|
||
|
||
// Exercicse 3 | ||
|
||
|
||
var goodPsswd = "1234567890"; | ||
var badPsswd = "1123456"; | ||
|
||
var noRepeatChar = function (password) { | ||
var UniquePassword = createUniq(password); | ||
if (password.length == UniquePassword.length){ | ||
return "Good Password"; | ||
} else { | ||
return "Bad Password"; | ||
} | ||
}; | ||
|
||
function createUniq (array){ | ||
return _.uniq(array); | ||
} | ||
|
||
console.log(noRepeatChar(goodPsswd)); | ||
console.log(noRepeatChar(badPsswd)); | ||
|
||
|
||
|
||
var goodPsswd = "1234567890"; | ||
var badPsswd = "1a234567890"; | ||
var onlyNumbers = function (password) { | ||
var testType = true; | ||
for (var i = 0; i < password.length; i++) { | ||
if (isNaN(parseInt(password[i]))){ | ||
testType = false; | ||
} | ||
} | ||
return testType; | ||
} | ||
|
||
console.log(onlyNumbers(goodPsswd)); | ||
console.log(onlyNumbers(badPsswd)); | ||
|
||
|
||
|
||
|
||
|
||
var goodPsswd = "1234567890"; | ||
var badPsswd = "12345678901234567890"; | ||
|
||
var trimPassword = function (password) { | ||
return _.join(_.slice(password, 0, 10), ''); | ||
} | ||
|
||
|
||
trimPassword(badPsswd); | ||
|
||
// Exercise 4 | ||
|
||
var novemberArtists = function (arr) { | ||
|
||
var novemberSongs = _.filter(arr, function(elem){ | ||
|
||
if (_.has(elem, 'month') && elem.month === 11) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}); | ||
|
||
|
||
return countArtist(novemberSongs); | ||
} | ||
|
||
function countArtist (arr) { | ||
var artistCounts = _.countBy(arr, 'artist'); | ||
|
||
var maxSongs = 0; | ||
var maxArtist = ''; | ||
|
||
for (var key in artistCounts) { | ||
if(artistCounts[key] > maxSongs) { | ||
maxSongs = artistCounts[key]; | ||
maxArtist = key; | ||
} | ||
|
||
} | ||
|
||
return maxArtist; | ||
|
||
} | ||
|
||
|
||
console.log(novemberArtists(abbeyRoadRecords)); | ||
|
||
|
||
var bestArtist = function (arr) { | ||
return countArtist(arr); | ||
}; | ||
|
||
console.log(bestArtist(abbeyRoadRecords)); | ||
|
||
|
||
var lastBeatlesSong = function (arr) { | ||
|
||
var beatlesSongs = _.filter(arr, function(elem) { | ||
return _.has(elem, 'artist') && elem.artist == "The Beatles"; | ||
}); | ||
|
||
return _.maxBy(beatlesSongs, 'year'); | ||
}; | ||
|
||
|
||
console.log(lastBeatlesSong(abbeyRoadRecords)); | ||
|
||
|
||
var sixtiesSong = function (arr) { | ||
var sixtiesSongs = _.filter(arr, function(elem) { | ||
return _.has(elem, 'year') && elem.year < 1970 && elem.year > 1959; | ||
}); | ||
|
||
var maxYear = _.maxBy(sixtiesSongs, 'year'); | ||
|
||
var lastYearSongs = _.filter(arr, function(elem) { | ||
return _.has(elem, 'year') && elem.year===maxYear.year; | ||
}); | ||
|
||
var maxMonth = _.maxBy(lastYearSongs, 'month'); | ||
return maxMonth; | ||
}; | ||
|
||
console.log(sixtiesSong(abbeyRoadRecords)); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good Job |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could've tried to use different Lodash methods for that part, something like:
var novemberArtists = function () {
return .uniq(.map(_.filter(abbeyRoadRecords, ["month", 11]), "artist"));
};
console.log(novemberArtists());