How can I write javascript like this ruby code (array matching)? [duplicate] - javascript

This question already has answers here:
Simplest code for array intersection in javascript
(40 answers)
Closed 9 years ago.
This is my ruby code.
array1= [1,2,3,4,5]
array2= [2,3,4,5,6]
if (array1 & array2).size == 4
puts "4 match"
How can I write the same thing in javascript? Is there any material like ruby-doc in javascript?

There isn't a native method do do it.
Have a look at here : Simplest code for array intersection in javascript
The best documentation I know about javascript and html5 is the Mozilla developer network.

Related

Split string by arithmetic operators [duplicate]

This question already has answers here:
How do I split a string with multiple separators in JavaScript?
(25 answers)
Closed 3 years ago.
I have a string "str1+str2-str3*str4".
I want to split it so I get an array
['str1','+','str2','-','str3','*','str4'].
Could someone help provide a solution?
If JS split lets capture groups become elements, then this should work
/([-+*\/])/
if not, I suggest using a regular find all type thing
using this
/([-+*\/]|[^-+*\/]+)/
otherwise, I'll just delete this.

What does ## mean in Javascript? [duplicate]

This question already has answers here:
What does ## ("at at") mean in ES6 JavaScript?
(1 answer)
JS variable starting with "#"
(4 answers)
Closed 4 years ago.
When I look through the MDN docs I sometimes notice ##. For example the Set documentation has links to get Set[##species] and Set.prototype[##iterator]()
What does ## mean?
(Also how do you say it? "AT-AT" would make for a great Star Wars reference)

What does |0 do in Javascript? [duplicate]

This question already has answers here:
What does the "|" (single pipe) do in JavaScript?
(5 answers)
What is this asm style "x | 0" some javascript programmers are now using?
(4 answers)
Closed 7 years ago.
I have been looking into asm.js to use for a project recently, and I noticed that very often the asm.js compiled code will end a statement with |0;, even seemingly redundantly as in the statement i = i|0;
This is not something I have encountered in Javascript code before. What is it for?
EDIT
I don't believe this is duplicate. I know what a bitwise or is. I am specifically asking here why one might use it to or with a 0 before assignment. What purpose does that serve?
Convert to integer and apply a bitwise or with 0. Basically a short form of Math.floor().

What is difference in JavaScript and jquery? [duplicate]

This question already has answers here:
What is the difference between JavaScript and jQuery? [closed]
(6 answers)
Closed 7 years ago.
I have 1 year of experience in ui devoloper and i have to sweech my compony,
SO when i attened 1st interview the interviewer ask me one question i.e.
In your application you use javascript or Jquery or both,so i am not give him a proper answer so please anyone give me the answer for this question.
Pure javascript also known as vanilla js (like a joke). And pure js works faster than frameworks based on js.
There is a compartment of frameworks and pure js http://vanilla-js.com/. But using frameworks is easier than pure js.

Is there a program that will auto format my javascript? [duplicate]

This question already has answers here:
Closed 13 years ago.
Duplicate:
Javascript Beautifier
Is there a way I can auto format my javascript so its readable?
I have a javascript file that is just one line but about a million columns white. I don't want to go through and tab through each function just so I can read it.
Anyone know of a program that will do this for me?
Thanks!
On OS X use Textmate with the JavaScript bundle.

Categories