I am working on a quiz where I have three unordered lists of images stored in arrays. The goal is to drag and drop the images into the correct columns or arrays.
var arrays = [
['apple_0.jpg', 'orange_1.jpg', 'banana_0.jpg', 'pear_4.jpg', 'fish_5.jpg',
'pancake_7.jpg', 'taco_8.jpg', 'pizza_9.jpg'],
['taco_2.jpg', 'fish_5.jpg', 'apple_0.jpg', 'pizza_3.jpg'],
['banana_6.jpg', 'pizza_4.jpg', 'fish_3.jpg', 'apple_0.jpg']
];
var result = arrays.shift().filter(function(v) {
return arrays.every(function(a) {
return a.indexOf(v) !== -1;
});
});
document.write('<pre>' +
JSON.stringify(result,null,4)
+ '</pre>');
Currently, the code works only when the full object name matches exactly, for example, "apple_0.jpg".
Objective: My objective is to find all instances of apple, fish, and pizza regardless of the suffix (_[variable].jpg).
For example, searching for substrings within the object array.