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
320 changes: 320 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions src/every.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,34 @@
// { name: 'Candy', nutritious: true }
// ]
// Expected Output: true
function allNutritious (items) {

function allNutritious(items) {
return items.every(function (x) {
return x['nutritious']
});
}

// Sample Input:
// [
// 10,
// 14,
// "23"
// ]
// Expected Output: false
function allOfOneType (items) {

function allOfOneType(items) {
return items.every(function (x, index, array) {
var y = typeof (x) === typeof (array[0]);
if (y) {
if (array[0].length === undefined) {
if (x.length !== undefined) {
y = false
}
} else {
if (x.length === undefined) {
y = false
}
}
}
return y
})
}

module.exports = { allNutritious, allOfOneType }
13 changes: 11 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(num){
return num % 2 !== 0
})
}

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

var y = languages.filter(function(x){
if(x.id == id){
return x
}else{
return null
}
})
return y[0] == null?null:y[0]
}

module.exports = { onlyOdd, findById }
Loading