Message from JavaScript talks

May 2017

— 

// Checks if all elements of searchArray exist in targetArray
function includesAll (targetArray, searchArray) {
assert(Array.isArray(targetArray), "Parameter 1 must be an Array.", TypeError);
assert(Array.isArray(searchArray), "Parameter 2 must be an Array.", TypeError);
var uniqueMatches = [];
for (character in searchArray) {
if (!uniqueMatches.includes(character) && targetArray.includes(character)) {
uniqueMatches.push(character);
}
}
return uniqueMatches.length >= searchArray.length;
}

Message permanent page

— 

That check above never runs if these don't pass:

// Deduce if the String is definitely not in the Set from basic data.

if (charArray.length !== 0

    && uniquesLength !== 0

    && listLength !== 0

    && list.hasOwnProperty(charArray[0])

    && list[charArray[0]].hasOwnProperty([charArray.length])

  ) {

— For "Hello", it checks for this type of path in the set:

{
H: {
5: {
// Word may exist in here
}
}
}

— So as you can probably tell, construction of the set dictates where in the set we conduct the search

— Of course if you have a set with only words which start with H, and are of all the same length, it will be only as effective as a linear search on a flat array

Message permanent page

— But for diverse datasets, this will improve search efficiency massively

— You could also target by multiple letters, instead of just the first. I'm not sure how much more effective that would be

Message permanent page

— All these checks are ordered from "least expensive" to "most expensive" too, so if we can deduce that the string is not in the set from a less expensive method, we just saved time :D

Message permanent page

— Put in js file, and module.exports the class

— Should follow this api:
s = new Set()
s.add(str)
s.has(str)
s.delete(str)

— Sure

— Made the test better