Skip to content

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
wants to merge 1 commit into
base: master
Choose a base branch
from
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
186 changes: 186 additions & 0 deletions starter-code/lib/excersise.js
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));
Copy link

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());



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));

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Job

1 change: 1 addition & 0 deletions starter-code/lodash.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.16.4/lodash.js"></script>
<script src="./lib/abbeyRoad.js"></script>
<script src="./lib/harryPotter.js"></script>
<script src="./lib/excersise.js"></script>
</head>

<body>
Expand Down