JSFiddle - React, Tailwind, and code Playground
JavaScript
function Test(inputData, inputDictionary) {
const dictionarySet = new Set(inputDictionary);
try {
return inputData
.sort((item1, item2) => item1.geometry[0] - item2.geometry[0])
.map(({text}) => {
if (!dictionarySet.has(text)) throw new Error('Unreadable message');
return text;
}).join(' ');
} catch(e) {
return e.message;
}
}
console.log(Test([
{
"geometry": [10, 20],
"text": "James"
},
{
"geometry": [20, 40],
"text": "Bond"
},
{
"geometry": [5, 40],
"text": "Bond"
}
],
["James", "Bond"]));