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
8 changes: 6 additions & 2 deletions src/every.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
// ]
// Expected Output: true
function allNutritious (items) {

return items.every(function(item){
return item.nutritious == true;
});
}

// Sample Input:
Expand All @@ -19,7 +21,9 @@ function allNutritious (items) {
// ]
// Expected Output: false
function allOfOneType (items) {

return items.every(function(item){
return (typeof item === typeof items[0]) && (Array.isArray(item) === Array.isArray(items[0])) ;
});
}

module.exports = { allNutritious, allOfOneType }
20 changes: 18 additions & 2 deletions src/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// Sample Input: [ 11, 44, 78, 99 ]
// Expected Output: [ 11, 44 ]
function onlyOdd (numbers) {

return numbers.filter(function(number){
return number % 2 === 1;
});
}

// Sample Input:
Expand All @@ -16,7 +18,21 @@ function onlyOdd (numbers) {
// Expected Output:
// { id: 42, name: 'Clojure' }
function findById (languages, id) {

let lang = languages.filter(function(language){
if(!language){
return null;
}
if(language.id === id){
return {id: language.id, name: language.name};
} else {
return null;
}
}, id);
if(lang[0] !== undefined){
return lang[0];
} else {
return null;
}
}

module.exports = { onlyOdd, findById }
8 changes: 6 additions & 2 deletions src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
// ]
// Expected Output: ['Alex Mali', 'dvsn', 'Mura Masa']
function justArtists (songs) {

return songs.map((song)=>{
return song.artist;
});
}

// Sample Input:
Expand All @@ -24,7 +26,9 @@ function justArtists (songs) {
// { name: 'Banana Bunches', price: 2.33, quantity: 2 }
// ]
function toObject (candies) {

return candies.map((candy)=>{
return {name: candy[0], price: candy[1], quantity: candy[2]};
});
}

module.exports = { justArtists, toObject }
19 changes: 17 additions & 2 deletions src/reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
// ]
// Expected Output: [ 10, 20, 30, -10, -4, 0, 10, 100, 1000 ]
function flatten (matrix) {

return matrix.reduce((flat, matrixEntry) => {
return flat.concat(matrixEntry);
}, []);
}

// Sample Input:
Expand All @@ -24,7 +26,20 @@ function flatten (matrix) {
// cell: [ '(333) 655-4555', '(333) 455-5555', '(333) 255-5555' ]
// }
function consolidate (numbers) {

return numbers.reduce((phoneNumbers, numberEntry) => {
if(!numberEntry){
return phoneNumbers;
}
if(!phoneNumbers.home){
phoneNumbers.home = [];
}
if(!phoneNumbers.cell){
phoneNumbers.cell = [];
}
phoneNumbers.home.push(numberEntry.phone.home);
phoneNumbers.cell.push(numberEntry.phone.cell);
return phoneNumbers;
}, {});
}

module.exports = { flatten, consolidate }
10 changes: 8 additions & 2 deletions src/some.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
// Sample Input: [ 10, 20, 30, 40, -50 ]
// Expected Output: true
function anyAreNegative (numbers) {

return numbers.some((number) => number < 0)
}

// Sample Input: [ 'Once', 'upon', 'a', 'time', '' ]
// Expected Output: true
function includesFalseyValues (items) {

return items.some(item => {
if(!item){
return true;
} else {
return false;
}
})
}

module.exports = { anyAreNegative, includesFalseyValues }