Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var names = [
- "Alex",
- "Matthew",
- "Joe"
- ]
- names.every(function(name){
- return name.length > 4
- })
- names.some(function(name){
- return name.length > 4
- })
- // text input field
- function Field(value) {
- this.value = value
- }
- Field.prototype.validate = function() {
- return this.value.length > 0
- }
- var username = new Field("2cool")
- var password = new Field("8sdfb36_@eef")
- // what if there will be much more fields. Like 20 fields
- // here the every or some function would be helpful
- username.validate() && password.validate()
- var fields = [username, password]
- var formsAreValid = fields.every(function(field) {
- return field.validate()
- })
- if ( formsAreValid ) {
- // user can subscribe
- } else {
- // show error message
- }
- // Online Course Tests
- // every
- var users = [
- { id: 21, hasSubmitted: true },
- { id: 62, hasSubmitted: false },
- { id: 4, hasSubmitted: true }
- ];
- var hasSubmitted = users.every(function(user) {
- return user.hasSubmitted === true
- })
- // some
- var requests = [
- { url: '/photos', status: 'complete' },
- { url: '/albums', status: 'pending' },
- { url: '/users', status: 'failed' }
- ];
- var inProgress = requests.some(function(request){
- return request.status === 'pending'
- })
Add Comment
Please, Sign In to add comment