JSFiddle - React, Tailwind, and code Playground

JavaScript

function Test(inputData, inputDictionary) {
 const hashMap = {};
  inputData.sort((item1, item2) => item1.geometry[0] - item2.geometry[0]);
  inputDictionary.forEach(elem => {
  	hashMap[elem] = true;
  });

  let textMessages = "";

  for(let i = 0; i < inputData.length; i++){
    	if(!hashMap[inputData[i]["text"]]){
        	return "Unreadable message";
       } else {
       	textMessages += inputData[i]["text"] + (i === inputData.length - 1 ? "" : " ");
       }
    }

    return textMessages;
}

console.log(Test([
        {
            "geometry": [10, 20],
            "text": "James"
        },
        {
            "geometry": [20, 40],
            "text": "Bond"
        },
        {
            "geometry": [5, 40],
            "text": "Bond"
        }
    ],
    ["James", "Bond"]));