8
edits
(→API) |
Master Quiz (talk | contribs) m (→Fetch) |
||
Line 63: | Line 63: | ||
This is a function that uses the [[wikipedia:XMLHttpRequest#Fetch_alternative|Fetch]] API to send a request given as input a string code: | This is a function that uses the [[wikipedia:XMLHttpRequest#Fetch_alternative|Fetch]] API to send a request given as input a string code: | ||
<source lang=js> | <source lang=js> | ||
async function | async function executeAPL(code) { | ||
const res = await fetch("https://tryapl.org/Exec", { | const res = await fetch("https://tryapl.org/Exec", { | ||
method: 'POST', | method: 'POST', | ||
Line 75: | Line 75: | ||
// To call the function you must use an async/await statement. | // To call the function you must use an async/await statement. | ||
(async () => { | (async () => { | ||
let resultSum = await | let resultSum = await executeAPL(`2+2`); | ||
let reshape = (await | let reshape = (await executeAPL(`2 2⍴⍳${resultSum}`)) | ||
.map(row => row.split` `.map(x => +x)); | .map(row => row.split` `.map(x => +x)); | ||
let sumReduce = (await | let sumReduce = (await executeAPL(`+/ (↑⍣≡0∘⎕JSON) '${JSON.stringify(reshape)}'`)) | ||
.map(row => row.split` `.map(x => +x)); | .map(row => row.split` `.map(x => +x)); | ||
console.log(sumReduce); | console.log(sumReduce); | ||
Line 91: | Line 91: | ||
let hash = 'b#I;?EZD=8s=YfFKk=g-u;6Uc`dwiu3Val5Gt`%rAhCWd4~6Z_WwqIp<R`FEoA*lr*Z0=uC*HY#_2JbY'; | let hash = 'b#I;?EZD=8s=YfFKk=g-u;6Uc`dwiu3Val5Gt`%rAhCWd4~6Z_WwqIp<R`FEoA*lr*Z0=uC*HY#_2JbY'; | ||
async function | async function executeAPL(code) { | ||
const res = await fetch("https://tryapl.org/Exec", { | const res = await fetch("https://tryapl.org/Exec", { | ||
method: 'POST', | method: 'POST', | ||
Line 102: | Line 102: | ||
(async () => { | (async () => { | ||
let result = await | let result = await executeAPL(`increment 27`); | ||
console.log(result); | console.log(result); | ||
})(); | })(); |
edits