Comments

Lenry Kabu7 hours ago

const solve = (intArray, sequence) => {
  return intArray.join("").includes(sequence.join(""));
};

Very cheeky!!

Muhammad Aamira month ago

This solution deals with duplication in intArray as well. solve([3,3,4], [3,4]) // true

const solve = (intArray, sequence) => {
  sequenceFound = false;
  for (let arrIndex = 0; arrIndex < intArray.length; arrIndex++) {
    if (intArray[arrIndex] === sequence[0]) {
      sequenceFound = true;
      for (let sIndex = 1; sIndex < sequence.length; sIndex++) {
        if (sequence[sIndex] !== intArray[arrIndex + sIndex]) {
          sequenceFound = false;
          break;
        }
      }
    }
    if (sequenceFound) {
      break;
    }
  }
  return sequenceFound;
};

Fadi Quader3 months ago

const solve = (intArray, sequence) => {

  const allIndexes = intArray.reduce((acc, el, i) => (el === sequence[0] ? [...acc, i] : acc), []);
  if (!allIndexes.length) return [];
  
  for(let index = 0; index < allIndexes.length; index++) {
    const firstIndex = allIndexes[index];
    const seq = intArray.slice(firstIndex, sequence.length + firstIndex);

    const seqFound = seq.every((_, i, self) => self[i] === sequence[i])
    if (seqFound) return true;    
  }
  
  return false
};

Reza Indra G3 months ago

const solve = (intArray, sequence) => {
  let isSeq = false;
  for (let i = sequence.length-1; i < intArray.length; i++) {
    let idxSeq = 0;
    const seq = [];
    for (let j = i-(sequence.length-1); j <= i; j++) {
      if (intArray[j] === sequence[idxSeq]) {
        seq.push(intArray[j]);
      }
      idxSeq++;
    }
    if (seq.length === sequence.length) {
      isSeq = true
    }
  }
  return isSeq;
};

Reza Indra G3 months ago

const solve = (intArray, sequence) => { let isSeq = false; for (let i = sequence.length-1; i < intArray.length; i++) { let idxSeq = 0; const seq = []; for (let j = i-(sequence.length-1); j <= i; j++) { if (intArray[j] === sequence[idxSeq]) { seq.push(intArray[j]); } idxSeq++; } if (seq.length === sequence.length) { isSeq = true } } return isSeq; };

Ali Sequeira5 months ago

const solve = (intArray, sequence) => {
  const k = sequence[0]
    const index = intArray.indexOf(k);
    const subArray = intArray.splice(index, sequence.length)
    let response = true;
  for(let i = 0 ; i < subArray.length; i++){
    subArray[i] !== sequence[i] ? response = false : response
  }
  return response;
};

Sarthak Joshi7 months ago

`const solve = (intArray, sequence) => { let i = 0; let j = 0;

while (i < intArray.length) {
    if (intArray[i] === sequence[j]) {
        j++;
    } else {
        j = 0;
    }
    i++
    if (j === sequence.length) return true
}
return false

};`

Mac Villegas8 months ago

const solve = (intArray, sequence) => { const arr = intArray.join(""); const seq = sequence.join(""); return arr.includes(seq); };

Irakli Iremashvili8 months ago

A dirty solution, but still workng :D

const solve = (intArray, sequence) => { return !!intArray.join().match(sequence.join()) };

Bryan Guilas8 months ago

const solve = (arr1, arr2) => {
  let i = 0
  let j = 0
  let count = 0
  while(i < arr1.length) {
   if (arr1[i] === arr2[j]) {
       count++;
       j++;
     } else {
       count = 0;
       j = 0; 
     }
    i++;
    if(count === arr2.length) return true;
  }
  return false;
};

withdrawal payment solutions9 months ago

const solve = (intArray, sequence) => { return intArray.filter(boolean => intArray.includes(sequence)); };

moderator Soft2 months ago

Are you sure about it's working?

Wagner CS Filho10 months ago

const solve = (intArray, sequence) => {
  let index = -1;
  return sequence.reduce((prev, seq) => {
    const currIndex = intArray.indexOf(seq)
    prev = currIndex > -1 && (currIndex-1 === index || index === -1);
    index = currIndex;
    return prev;
  }, false)
};

Samuel Egwurubea year ago

const solve = (intArray, sequence) => {
  let res
for(let i = 1; i<sequence.length; i++){
  if(intArray.indexOf(sequence[i]) - intArray.indexOf(sequence[i-1]) == 1){
    res = true
  }else{
    return false
  }
}
return res
};

Abdelhamid Ismail2 years ago

const solve = (intArray, sequence) => {
  return intArray.join('').includes(sequence.join(''))
};

Coordinator proactivea year ago

If the intArray is joined on a comma, the sequence array can be passed to include() as is. Don't know exactly why:

const solve = (intArray, sequence) => {
  return intArray.join().includes(sequence);
};

SAS2 years ago

const solve = (intArray, sequence) => { return intArray.toString().includes(sequence.toString()) };

Kara Diaby2 years ago

const solve = (intArray, sequence) => { const [str1,str2 ] = [intArray.join(""), sequence.join("")] return str1.includes(str2) };

Savings Account Ergonomic2 years ago

intArray.join("").split(sequence.join("")).length==2;