zoukankan      html  css  js  c++  java
  • [Javascript] Array methods in depth

    some returns a boolean value after passing each item in the source array through the test function that you pass in as the first parameter. This makes it well suited to the types of queries that require a simple yes or no answer. In this lesson we look at 2 practical use-cases for some. The first shows how it can be used with a ternary operator to switch a class on an element & the second shows how some can be used in an if conditional.

     
    var tasks = [
      {
        title: "A",
        completed: true
      },
      {
        title: "B",
        completed: false
      },
      {
        title: "C",
        completed: true
      }
    ];
    
    function addTask(title) {
      if(tasks.some( task => task.title === title)){
        return ;
      }
      
      tasks.push({title: title, completed: false});
    }
    
    addTask('B');
    
    console.log(tasks);
  • 相关阅读:
    RMQ
    LCA 笔记
    LUCAS 定理
    topcoder 643 DIV2
    BZOJ 1071组队
    Codeforces Round #283 (Div. 2)
    topcoder 642
    Codeforces Round #278 (Div. 2)
    树链剖分
    Codeforces Round #277 (Div. 2)
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5105801.html
Copyright © 2011-2022 走看看