Created
April 15, 2020 01:48
-
-
Save djD-REK/72f60bf652c4013a4588ba1a62c07490 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SIZE_OF_ARRAY = 10 | |
const anArray = Array.from(Array(SIZE_OF_ARRAY + 1).keys()) | |
anArray.shift() | |
console.log(anArray) // Array(10) [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] | |
const SEARCH_VALUE = SIZE_OF_ARRAY / 2 // i.e. 5 | |
anArray.includes(SEARCH_VALUE) // true | |
anArray.filter((x) => x === SEARCH_VALUE).length > 0 // true | |
anArray.some((x) => x === SEARCH_VALUE) // true | |
let foundIt = false | |
for (let index = 0; index < anArray.length; index++) { | |
if (anArray[index] === SEARCH_VALUE) { | |
foundIt = true | |
break | |
} | |
} | |
console.log( | |
`anArray.includes(${SEARCH_VALUE}) is ${anArray.includes(SEARCH_VALUE)}` | |
) | |
console.log( | |
`anArray.filter((x) => x === ${SEARCH_VALUE}).length > 0 is ${ | |
anArray.filter((x) => x === SEARCH_VALUE).length > 0 | |
}` | |
) | |
console.log( | |
`anArray.some((x) => x === ${SEARCH_VALUE}) is ${anArray.some( | |
(x) => x === SEARCH_VALUE | |
)}` | |
) | |
console.log(`The variable foundIt from the for loop is ${foundIt}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment