arranage array from highest to lowest value [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I need to arrange an array from highest to lowest in a function
i have used array.sort but was informed that that was not allowed for my exerccise
function minmax(array){
var ar = array.sort().join();//I cant use array.join methood
return ar
}
Please help out

One solution could be to implement any of the popular sorting algorithms, but make the comparison used prioritize larger numbers. One example is this link, the code of which only needs a > flipped to a <.
Note that if this is a homework or school excercise, copying from anywhere is plagiarism and is generally discouraged.

Related

What is the time complexity of JavaScript methods? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Is there any resource to know the time complexity of natively defined array and string methods in JavaScript?
I have to do guess work while I am using them to solve algorithm, but I want to be sure about what is the time complexity of those functions?
This question has been answered previously:
Time Complexity for Javascript Methods in V8
In short, it's not specified and the time complexity for common JS methods can differ between browsers.
Worse yet, some methods might not even exist or will behave differently between different browsers and browser versions!

Why not Number.isNumber or Function.isFunction? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
Although javascript is a weakly typed language, in some scenarios is needed to ensure the data type. Currently many node packages depend on helper functions, e.g, isNumber and isFunction.
It'd be interesting if there were built-in methods for that like Array.isArray. Something like Number.isNumber or Function.isFunction.
What do you guys think about this?
You should not worry much about such. There are already a lot of methods. For your query, you can use Number.isNaN for checking number and use typeof to know if the given variable is a function.
You can check the following answers:
Is there any function like IsNumeric in JavaScript to validate numbers?
How can I check if a javascript variable is function type?
Array is a collection. The collection might refer to [...] or {...} and this is why there's Array.isArray to check if the given collection is array or not. But there's no other way arround for differentiating the function and the number between themselves. And this is perfect reason the javascript should not have such function.

Compare points in two grids [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have two raster with x points on it like this:
I have this data from each raster in a array like this:
[
[200,330],
[500,800]
]
How can i compare this data to figure out how many percent as equal this both grids to each other?
My idea is to generate a hash and compare this both hashes, but i don't have an idea how can i do this.
This idea comes from audio fingerprinting.
I will do this in swift or javascript.
Thanks you for each thought!
What you are looking for is to compute the similarity between two vectors.
In your case the vector looks like: [[x1,y1], [x2,y2], ...,[xn, yn]]
I would recommend Cosine Similarity.
The implementation is pretty straight forward, regardless the programming language.
(There are existing implementation of Cosine Similarity out there, for example In JavaScript)

how does getElementsByClassName() work under the hood? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I've tended to just loop over elements selectively to find elements of a specific class, but I'm curious if using getElementsByClassName (for applicable browsers) will increase performance at all.
How does it actually WORK?
I could easily run a test to check performance obviously, but I'm really curious what's going on in there anyway.

Array literal or string split? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Lets say you needed a hardcoded list of strings (the question here is not whether or not you should hard-code things).
Is there a reason to prefer this:
var things = 'a b see'.split(' ');
over this:
var things = ['a', 'b', 'see'];
Pros of first approach:
Easier to refactor data from code. (String is not language specific)
Pros of second approach:
Less prone to error (what if your string has a space in it?)
Easier to format automatically (can and probably should separate each string by newline)
Easier to get data from alternate sources in the future.
Signals intent more clearly
Tiny bit more efficient

Categories

Resources