The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Check If One JavaScript Array Is Included In Another One

TODO: Pull subtitle into page object

Notes

script_start_default_section script_end_default_section

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Check If One JavaScript Array Is Included In Another One


It doesn't look like you can do `.include()`` 
to find an array of numbers in another array. 

I didn't find what I was looking for with 
a quick search so I'm doing it like this

-- notes

- probably there are more elequent ways to
do this

- i've only got the visual tests you see
in the console in place. it works, but I want
to add more tests

- I don't expected this to work with multi
level nested arrays

- I've only tested this with numbers

-- script/
-- title: example
-- show

const findArrayInArray = (container, target) => {
  return container.some((el) => {
    return target.every((t, tIndex) => {
      if (el[tIndex] === t) {
        return true
      } else {
        return false
      }
    })
  })
}

const base = [ [4, 7] ]

const tango = [4, 7]
const foxtrot = [3, 7]

console.log(findArrayInArray(base, tango))
console.log(findArrayInArray(base, foxtrot))


-- /script


This didn't work

-- script/
-- title: test stuff to reexamine
-- show

const alfa = [[1, 2]]

const bravo = ["a"]

if (alfa.includes([1,2])) {
  console.log("hit")
} else {
  console.log("miss")
}

if (bravo.includes("a")) {
  console.log("hit")
} else {
  console.log("miss")
}

-- /script

-- ref
-- url: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some

-- ref
-- url: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every

-- ref
-- link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes


-- categories
-- JavaScript 


-- metadata
-- date: 2023-08-12 18:13:06
-- id: 2tu1wbkf
-- site: aws
-- type: post
-- status: draft