This solution is generated by ChatGPT, correctness is not guaranteed.

AI solution for JavaScript Coding Question on BFE.dev
159. implement promisify()

Here's one possible solution to implement promisify():

const promisify = (fn) => {
  return (...args) => {
    return new Promise((resolve, reject) => {
      fn(...args, (error, data) => {
        if (error) {
          reject(error)
        } else {
          resolve(data)
        }
      })
    })
  }
}

The promisify() function takes a function (fn) that has an error-first callback as its last argument. It returns a new function that returns a promise. When the new function is called, it calls the original function (fn) with the same arguments, and passes a callback function that resolves or rejects the promise based on the error or data received from the original function.

The returned promise can then be used to handle the data or error in a more streamlined way, without having to deal with the error-first callback.

Note that this is just one possible solution, and there are many different ways to implement promisify().