This file contains 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
// Array of students | |
const students = [{name: 'John', score: 50} , {name: 'Peter', score: 60}, {name: 'James', score: 55}]; | |
// Threshold Score | |
const passScore = 50; | |
// Test students | |
const studentsPassed = students.every(student => student.score >= passScore); | |
// Display status |
This file contains 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
// Create new array | |
const array = [2, 5, 10, 8, 20] | |
// Create test function | |
const testFunction = number => number % 5 === 0 | |
// Apply function | |
const result = array.some(testFunction) | |
// Display result |
This file contains 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
// Array of objects | |
const users = [{firstName: 'Peter', lastName: 'Parker'}, {firstName: 'Harry'}]; | |
// Verify properties of an object | |
let hasLastName = users.some(function(user){ | |
return !!user.lastName; | |
}) | |
// Output result | |
console.log(hasLastName); |
This file contains 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
// Array of names | |
const names = ['john', 'chris', 'mike', 'holly', 'will'] | |
// Convert to string | |
const stringNames = names.toString() | |
// Output string | |
console.log(stringNames) |
This file contains 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
// Create array with strings | |
const values = ['1', '2', '3', '4']; | |
// Convert array to string separated by a comma | |
const string = values.toString(); | |
// Output string | |
console.log(string); |
This file contains 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
// Create array of numbers | |
let array = [1, 2, 3, 4, 5] | |
// Double each number and display | |
array.forEach(function(number){ | |
console.log(number*2) | |
}) |
This file contains 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
// Create new array | |
const students = ['Jerry', 'Mary', 'Brenda', 'John']; | |
// Create empty array to be copied into | |
const classA = []; | |
// Copy names into new array | |
students.forEach(student => { | |
classA.push(student) | |
}); |
This file contains 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
// Array of dates | |
const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']; | |
// with for loop | |
for(i = 0; i < days.length; i++){ | |
console.log(days[i]); | |
} | |
console.log('----------------------') |
This file contains 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
// Create an array of names | |
const classNames = ['amazon', 'facebook', 'google', 'scotch'] | |
// Verify inclusion in classNames | |
let partOfClass = classNames.includes('microsoft') | |
// Output result | |
console.log(partOfClass) |
This file contains 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
// Weekdays | |
const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']; | |
// Random month | |
const month = 'May'; | |
// Verify inclusion in array | |
const isDay = days.includes(month); | |
// Output result |