loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.6135605027144355","path":"main.js","file":{"path":"main.js","content":{"asEncoding":{"base64":"Ly8gVGhpcyBwcm9ibGVtIHdhcyBhc2tlZCBieSBHb29nbGUuCi8vIEltcGxlbWVudCBpbnRlZ2VyIGV4cG9uZW50aWF0aW9uLiBUaGF0IGlzLCBpbXBsZW1lbnQgdGhlIHBvdyh4LCB5KSBmdW5jdGlvbiwgd2hlcmUgeCBhbmQgeSBhcmUgaW50ZWdlcnMgYW5kIHJldHVybnMgeF55LgovLyBEbyB0aGlzIGZhc3RlciB0aGFuIHRoZSBuYWl2ZSBtZXRob2Qgb2YgcmVwZWF0ZWQgbXVsdGlwbGljYXRpb24uCi8vIEZvciBleGFtcGxlLCBwb3coMiwgMTApIHNob3VsZCByZXR1cm4gMTAyNC4KZnVuY3Rpb24gcG93KHgsIHkpIHsKICAvLyBjb25zdCBiYXNlID0gcGFyc2VJbnQoeCkKICAvLyBjb25zdCBwb3dlciA9IHBhcnNlSW50KHkpCiAgCiAgLy8gbGV0IHByb2R1Y3QgPSAxCiAgLy8gZm9yIChsZXQgaSA9IDA7IGkgPCBwb3dlcjsgaSsrKSB7CiAgLy8gICBwcm9kdWN0ICo9IGJhc2UKICAvLyB9CiAgCiAgLy8gcmV0dXJuIHByb2R1Y3QKICByZXR1cm4geCAqKiB5Cn0KCmNvbnN0IGV4cGVjdGVkID0gMTAyNApjb25zdCBnaXZlbiA9IHBvdygyLCAxMCkKCnRlc3QoZXhwZWN0ZWQsIGdpdmVuKQoKZnVuY3Rpb24gdGVzdChleHBlY3RlZCwgZ2l2ZW4pIHsKICBpZiAoSlNPTi5zdHJpbmdpZnkoZXhwZWN0ZWQpICA9PT0gSlNPTi5zdHJpbmdpZnkoZ2l2ZW4pKSB7CiAgICBjb25zb2xlLmxvZygnVGVzdCBwYXNzZWQhJykKICB9IGVsc2UgewogICAgY29uc29sZS5sb2coSlNPTi5zdHJpbmdpZnkoZ2l2ZW4pICsgJyBzaG91bGQgaGF2ZSBiZWVuICcgKyBKU09OLnN0cmluZ2lmeShleHBlY3RlZCkpCiAgfQp9"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// This problem was asked by Google.
// Implement integer exponentiation. That is, implement the pow(x, y) function, where x and y are integers and returns x^y.
// Do this faster than the naive method of repeated multiplication.
// For example, pow(2, 10) should return 1024.
function pow(x, y) {
  // const base = parseInt(x)
  // const power = parseInt(y)
  
  // let product = 1
  // for (let i = 0; i < power; i++) {
  //   product *= base
  // }
  
  // return product
  return x ** y
}

const expected = 1024
const given = pow(2, 10)

test(expected, given)

function test(expected, given) {
  if (JSON.stringify(expected)  === JSON.stringify(given)) {
    console.log('Test passed!')
  } else {
    console.log(JSON.stringify(given) + ' should have been ' + JSON.stringify(expected))
  }
}
Native Browser JavaScript