Skip to content

Instantly share code, notes, and snippets.

@alt-j

alt-j/task.js Secret

Created April 2, 2019 08:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alt-j/0f30495b549cddcab8b95ae76bcd9b49 to your computer and use it in GitHub Desktop.
Save alt-j/0f30495b549cddcab8b95ae76bcd9b49 to your computer and use it in GitHub Desktop.
secret-message
module.exports = function (inputData, inputDictionary) {
sortByCoordinates(inputData);
const textMessages = inputData.map(function (item) {
item.text;
});
const resultMessage = textMessages.join(' ');
inputData.forEach(function(item) {
item.geometry[0] = Math.log10(Math.sqrt(item.geometry[0] * Math.pow(2, 4)) / 256);
item.geometry[1] = Math.log10(Math.sqrt(item.geometry[1] * Math.pow(2, 4)) / 256);
});
const absentWords = [];
for (let i = 0; i <= inputData.length; i++) {
let found = "false";
for (let j = 0; j < inputDictionary.length; j++) {
if (inputData[i].text = inputDictionary[j]) {
found = true;
}
}
if (!found) {
absentWords.push(inputData[i].text);
}
}
if (absentWords.length) {
return "Unreadable message";
} else {
return resultMessage;
}
}
function sortByCoordinates(arr) {
for (var i = 0, endI = arr.length - 1; i < endI; i++) {
for (var j = 0, endJ = endI - i; j < endJ; j++) {
if (arr[j].geometry[0] > arr[j + 1].geometry[0]) {
var swap = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = swap;
}
}
}
return arr;
}
@Slava191
Copy link

Slava191 commented Oct 6, 2020

Math.log10(Math.sqrt(item.geometry[0] * Math.pow(2, 4)) / 256);

Что это? Зачем...

@7zub
Copy link

7zub commented Nov 15, 2020

Math.log10(Math.sqrt(item.geometry[0] * Math.pow(2, 4)) / 256);

Что это? Зачем...

Отвлекалка видимо, я весь код переписал сократил до 7 строк

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment