Created
January 8, 2024 05:09
-
-
Save adarsh-gupta101/b5661dca096f8f3c2ffe3ad481b4d9cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dataParts = [ | |
[ | |
{ | |
"data": [ | |
".", | |
".", | |
".", | |
".", | |
".", | |
"➡➡➡", | |
"-", | |
"-", | |
"." | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
".", | |
"-", | |
"-", | |
"-", | |
".", | |
".", | |
".", | |
".", | |
"-", | |
"➡➡➡", | |
"-", | |
".", | |
".", | |
"." | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
"➡➡➡", | |
"-", | |
".", | |
"-", | |
"." | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
"➡➡➡", | |
"-", | |
"-", | |
".", | |
"-" | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"➡➡➡", | |
".", | |
".", | |
"-", | |
"." | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
".", | |
".", | |
"-", | |
"-", | |
"-", | |
"➡➡➡", | |
".", | |
".", | |
".", | |
"." | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
".", | |
".", | |
"➡➡➡", | |
"-", | |
"-", | |
"-" | |
] | |
}, | |
{ | |
"data": [ | |
"-", | |
"-", | |
".", | |
".", | |
".", | |
"➡➡➡", | |
".", | |
"-", | |
"-" | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
".", | |
"-", | |
"-", | |
"-", | |
"➡➡➡", | |
"-", | |
".", | |
"." | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
".", | |
"-", | |
"-", | |
"-", | |
".", | |
".", | |
".", | |
"-", | |
"-", | |
"➡➡➡", | |
"-", | |
"-", | |
".", | |
"." | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
".", | |
".", | |
".", | |
".", | |
".", | |
"➡➡➡", | |
".", | |
"." | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"➡➡➡", | |
"-", | |
"-", | |
"." | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
".", | |
".", | |
".", | |
"-", | |
"➡➡➡", | |
".", | |
"-", | |
"-", | |
"." | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
".", | |
"-", | |
"-", | |
"-", | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
"➡➡➡", | |
".", | |
".", | |
".", | |
"-" | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
".", | |
".", | |
".", | |
".", | |
"➡➡➡", | |
"-", | |
"-", | |
"." | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
".", | |
"➡➡➡", | |
"-", | |
".", | |
"-" | |
] | |
}, | |
{ | |
"data": [ | |
"-", | |
".", | |
".", | |
".", | |
".", | |
"➡➡➡", | |
".", | |
"." | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
".", | |
"-", | |
"-", | |
"-", | |
".", | |
".", | |
".", | |
".", | |
".", | |
"➡➡➡", | |
".", | |
"-", | |
"-" | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
".", | |
".", | |
".", | |
"➡➡➡", | |
".", | |
"-", | |
"-" | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
".", | |
".", | |
"➡➡➡", | |
"-", | |
".", | |
"-" | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
"-", | |
".", | |
".", | |
".", | |
"➡➡➡", | |
"-", | |
"-", | |
".", | |
"-" | |
] | |
}, | |
{ | |
"data": [ | |
"-", | |
"-", | |
"-", | |
".", | |
".", | |
"➡➡➡", | |
".", | |
".", | |
"-" | |
] | |
}, | |
{ | |
"data": [ | |
"-", | |
"-", | |
"-", | |
"-", | |
".", | |
"➡➡➡", | |
".", | |
"-", | |
"-", | |
"-" | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
".", | |
".", | |
".", | |
"-", | |
"-", | |
"➡➡➡", | |
"-", | |
"-", | |
"." | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
".", | |
".", | |
"-", | |
"-", | |
"➡➡➡", | |
".", | |
"-", | |
"-", | |
"-" | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
".", | |
"-", | |
"-", | |
"-", | |
".", | |
".", | |
"-", | |
"-", | |
"-", | |
"➡➡➡", | |
"-", | |
".", | |
"." | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
".", | |
".", | |
".", | |
".", | |
"➡➡➡", | |
".", | |
".", | |
".", | |
"-" | |
] | |
}, | |
{ | |
"data": [ | |
".", | |
"-", | |
"-", | |
"-", | |
"-", | |
".", | |
".", | |
".", | |
".", | |
"-", | |
"➡➡➡", | |
".", | |
"-", | |
"." | |
] | |
} | |
] | |
]; | |
// Extract the first five characters from each part's data | |
const extractedData = dataParts [0].map((part) => | |
// console.log(part.data) | |
part.data.join('').split('➡➡➡') | |
); | |
let keys = []; | |
extractedData.forEach((data) => { | |
a = data[0]; | |
// console.log(a) | |
if (data[0].length > 5) { | |
const half = data[0].slice(0, data[0].length / 2); | |
const Ohalf = data[0].slice(data[0].length / 2); | |
console.log(half, Ohalf); | |
let pos = morseToText(half) + morseToText(Ohalf); | |
// console.log(pos) | |
// keys.push ['position'] = pos; | |
// keys['value'] = morseToText(data[1]); | |
keys.push([pos, morseToText(data[1])]); | |
} else { | |
// keys['position'] = morseToText(data[0]); | |
// keys['value'] = morseToText(data[1]); | |
keys.push([morseToText(data[0]), morseToText(data[1])]); | |
} | |
// console.log(morseToText(data[0],morseToText(data[1]))) | |
}); | |
console.log(keys); | |
const sortedArray = keys.sort((a, b) => parseInt(a[0]) - parseInt(b[0])); | |
// Extract characters and join them | |
const resultString = sortedArray.map((pair) => pair[1]).join(''); | |
console.log(resultString); | |
function morseToText(morseCode) { | |
const morseCodeMap = { | |
'.-': 'A', | |
'-...': 'B', | |
'-.-.': 'C', | |
'-..': 'D', | |
'.': 'E', | |
'..-.': 'F', | |
'--.': 'G', | |
'....': 'H', | |
'..': 'I', | |
'.---': 'J', | |
'-.-': 'K', | |
'.-..': 'L', | |
'--': 'M', | |
'-.': 'N', | |
'---': 'O', | |
'.--.': 'P', | |
'--.-': 'Q', | |
'.-.': 'R', | |
'...': 'S', | |
'-': 'T', | |
'..-': 'U', | |
'...-': 'V', | |
'.--': 'W', | |
'-..-': 'X', | |
'-.--': 'Y', | |
'--..': 'Z', | |
'-----': '0', | |
'.----': '1', | |
'..---': '2', | |
'...--': '3', | |
'....-': '4', | |
'.....': '5', | |
'-....': '6', | |
'--...': '7', | |
'---..': '8', | |
'----.': '9', | |
'/': ' ', | |
}; | |
// Split Morse code into individual codes | |
const codes = morseCode.split('➡➡➡'); // into groups of five characters | |
// console.log(codes) | |
// Convert each Morse code to its corresponding character | |
const text = codes.map((code) => morseCodeMap[code] || '').join(''); | |
return text; | |
} | |
const submitChainCode = async () => { | |
try { | |
const response = await fetch("https://exam.ankush.wiki/answers", { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json", | |
}, | |
body: JSON.stringify({ chaincode: "CDJPGIWUJGQHGRIGWKKFVDZBWVQO" }), | |
}); | |
const data = await response.json(); | |
console.log("Response from /answers:", data); | |
} catch (error) { | |
console.error("Error submitting chain code:", error.message); | |
} | |
}; | |
function getData(part) { | |
const fetchData = async (i, results) => { | |
try { | |
const response = await fetch(`https://exam.ankush.wiki/data?part=${i}`); | |
const data = await response.json(); | |
console.log(data); | |
// Collect the result | |
results.push(data); | |
// Continue fetching for the next part after a delay | |
if (i < part) { | |
setTimeout(() => fetchData(i + 1, results), 2500); | |
} else { | |
// Return the results array when all fetch requests are completed | |
console.log('All fetch requests completed:', results); | |
} | |
} catch (error) { | |
console.error(`Error fetching data for part ${i}:`, error.message); | |
} | |
}; | |
// Start fetching from part 1 | |
fetchData(1, []); | |
} | |
// Example usage | |
getData(28); // Replace 10 with the desired number of parts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment