Skip to main content
se añadieron 51 caracteres en el cuerpo
Origen Enlace

esto es una menera mucho más sencilla que encontré:

  function work (arr){
      let target = arr.sort((a,b) => a-b).pop();
      
      return isContains(arr, target);

      function isContains(arr, target){
        if(arr.length === 0){
            return target===0;
        }
        let head = arr[0]
        let tail = arr.slice(1);

        return isContains(tail, target - head) || isContains(tail, target);
      }

  }
  console.log(work([4,6,23,10,1,3]))

  function work (arr){
      let target = arr.sort((a,b) => a-b).pop();
      
      return isContains(arr, target);

      function isContains(arr, target){
        if(arr.length === 0){
            return target===0;
        }
        let head = arr[0]
        let tail = arr.slice(1);

        return isContains(tail, target - head) || isContains(tail, target);
      }

  }
  console.log(work([4,6,23,10,1,3]))

esto es una menera mucho más sencilla que encontré:

  function work (arr){
      let target = arr.sort((a,b) => a-b).pop();
      
      return isContains(arr, target);

      function isContains(arr, target){
        if(arr.length === 0){
            return target===0;
        }
        let head = arr[0]
        let tail = arr.slice(1);

        return isContains(tail, target - head) || isContains(tail, target);
      }

  }
  console.log(work([4,6,23,10,1,3]))

se eliminaron 48 caracteres en el cuerpo
Origen Enlace

esto es una forma mucho más sencilla:

  function work (arr: number[]){
      let target = arr.sort((a,b) => a-b).pop();
      
      return isContains(arr, target);

      function isContains(arr, target){
        if(arr.length === 0){
            return target===0;
        }
        let head = arr[0]
        let tail = arr.slice(1);

        return isContains(tail, target - head) || isContains(tail, target);
      }

  }
  console.log(work([4,6,23,10,1,3]))

esto es una forma mucho más sencilla:

  function work (arr: number[]){
      let target = arr.sort((a,b) => a-b).pop();
      
      return isContains(arr, target);

      function isContains(arr, target){
        if(arr.length === 0){
            return target===0;
        }
        let head = arr[0]
        let tail = arr.slice(1);

        return isContains(tail, target - head) || isContains(tail, target);
      }

  }
  console.log(work([4,6,23,10,1,3]))

  function work (arr){
      let target = arr.sort((a,b) => a-b).pop();
      
      return isContains(arr, target);

      function isContains(arr, target){
        if(arr.length === 0){
            return target===0;
        }
        let head = arr[0]
        let tail = arr.slice(1);

        return isContains(tail, target - head) || isContains(tail, target);
      }

  }
  console.log(work([4,6,23,10,1,3]))

Origen Enlace

esto es una forma mucho más sencilla:

  function work (arr: number[]){
      let target = arr.sort((a,b) => a-b).pop();
      
      return isContains(arr, target);

      function isContains(arr, target){
        if(arr.length === 0){
            return target===0;
        }
        let head = arr[0]
        let tail = arr.slice(1);

        return isContains(tail, target - head) || isContains(tail, target);
      }

  }
  console.log(work([4,6,23,10,1,3]))