Advertisement
tamarin_vs19

Untitled

Jan 29th, 2022 (edited)
1,377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict'
  2.  
  3. module.exports = function (inputData, inputDictionary) {
  4.     sortByCoordinates(inputData);
  5.  
  6.     const textMessages = inputData.map(function (item) {
  7.         item.text;
  8.     });
  9.  
  10.     // inputData.forEach(function(item) {
  11.     //     item.geometry[0] = Math.log10(Math.sqrt(item.geometry[0] * Math.pow(2, 4)) / 256);
  12.     //     item.geometry[1] = Math.log10(Math.sqrt(item.geometry[1] * Math.pow(2, 4)) / 256);
  13.     // });
  14.  
  15.     const absentWords = [];
  16.     for (let i = 0; i <= textMessages.length; i++) {
  17.         let found = false;
  18.         for (let j = 0; j < inputDictionary.length; j++) {
  19.             if (textMessages[i] === inputDictionary[j]) {
  20.                 found = true;
  21.             }
  22.         }
  23.         if (found) {
  24.             absentWords.push(inputData[i].text);
  25.         }
  26.     }
  27.     const resultMessage = absentWords.join(' ');
  28.  
  29.     if (absentWords.length < textMessages.length) {
  30.         return "Unreadable message";
  31.     } else {
  32.         return resultMessage;
  33.     }
  34. }
  35.  
  36. function sortByCoordinates(arr) {
  37.     arr.sort((a, b) => {
  38.         a.geometry[0] < b.geometry[0];
  39.     })
  40.     // for (var i = 0, endI = arr.length - 1; i < endI; i++) {
  41.     //     for (var j = 0, endJ = endI - i; j < endJ; j++) {
  42.     //         if (arr[j].geometry[0] > arr[j + 1].geometry[0]) {
  43.     //             var swap = arr[j];
  44.     //             arr[j] = arr[j + 1];
  45.     //             arr[j + 1] = swap;
  46.     //         }
  47.     //     }
  48.     // }
  49.     return arr;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement