Skip to content

Tag: javascript

Global not defined when running a JS script in a Java application

I have a js script which I want to execute in my Java application. I have tried to use the Chromedriver API to do this But it throws the following exception: I am so confused because the script can simply run with node xx.js Does this mean the js which uses the global object cannot execute in a Java applicati…

How to filter and then aggregate results in pure Javascript

Say you have two arrays and want to find the most visited group (or groups – limit will be given) in from: four legs = 90 two legs = 160 no legs = 100 six = 90 eight = 160 many legs = 1000 something not listed yet Expected answer “many legs” for top 1. I have written my own

Why doesn’t Object.setProtoypeOf work on functions?

Let’s say we have the below code: why doesn’t Object.setPrototypeOf work on function if all all function in JavaScript are also objects? Answer The setPrototypeOf method works just fine on functions, you can now do EighthGrader.sayName() (which will say the EightGrader function’s .name) and …

Merge sort time complexity check

Hello guys I was learning about the merge sort so I wrote this function that takes 2 arrays and merges them sorted. Can someone tell me the time complexity of this function? I thought it would be O(n^2) as I am using shift inside a while loop. Is that correct or am I missing something here? Answer The worst c…