What is !+[]+!+[] in javascript? [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Hi i was reading a article and found pretty strange results the below code in javascript return 2.
!+[]+!+[]
Can anyone please explain.

Breaking down the expression into the correct order of operations, you have:
(!(+[])) + (!(+[]))
First things first, [] is cast to a number by +, which results in 0. Don't ask me why, it just does :p Probably buried in the specification somewhere.
!0 is simply true
So you end up with true + true, which again casts to numbers, resulting in 1 + 1 = 2
To get nine, you'd need nine repetitions:
!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[] == 9

Related

How to separate a string into a sentence without a proper patern [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
The community is reviewing whether to reopen this question as of 2 years ago.
Improve this question
I have a data that looks like this
Huawei Y7P Art-L28 (4/64gb) (AAAAAAAAAAAAAA) EXP:02/19/2020
Huawei Y9 prime 2019 (BBBBBBBBBBBBBBB) EXP:07/17/2019
Oppo A31 4gb/128gb (CCCCCCCCCCCCCCC)
Vivo Y15 5000mah 4GB/64GB (1901) (DDDDDDDDDDDDDDD) EXP:06/14/2019
And the I want to get this data
AAAAAAAAAAAAAA
BBBBBBBBBBBBBBB
CCCCCCCCCCCCCCC
DDDDDDDDDDDDDDD
Basically what I want to happen is to extract the data from the set of word but my problem here is that its very unpredictable. It has no pattern at all so its hard to separate the string.
Assuming that you need a substring in last parenthesis:
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(column, '(', -1), ')', 1)
FROM source_table

Replace thousand number with 0 on an integer [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 3 years ago.
Improve this question
I need an easy solution, in javascript, to remove thousands from an integer
for example:
29492 => 20492
1024 => 24
12345 => 10345
How could i do this easily ? the shorter/clearer the better
Even if I agree with Get Off My Lawn, you could have a solution that wok for both, with simple use of modulo.
x = x - (x%10000) + (x%1000)
//29492 => 29492 - 9492 + 492

Finding a faster way of checking characters in js [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
I'm trying to make something that gives an output based on your input. I would like it to take every letter and produce something with the next letter in the alphabet. So if I entered "Hello" it would produce "Ifmmp". The only way I can think to do this is with a series of ifs and else ifs, but I would like to know if there is a faster way.
You can use the String.fromCharCode feature. For example:
let myChar = 'c';
let nextChar = String.fromCharCode(myChar.charCodeAt(0)+1);
console.log(nextChar) // 'd'
In your case, you would replace 'c' with your character variable.

Email Regex for Javascript Which not start with Number [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
^[a-zA-Z]\w+#[a-zA-Z_]+?\.[a-zA-Z]{2,4}$
i had tried this regex for email but it allow following cases
123#mail.com
example.mail#mail.com
Here is the code which searches for the number at the start.
If number is matched it prints message in console.
let regex = /^[0-9]/;
let object = [{email:'123#mail.com'},{email:'example.mail#mail.com'}];
for(let i =0;i<object.length;i++){
if(object[i].email.match(regex)){
console.log('E-mail ',object[i].email,' is not valid.')
}
}
This is the used regex: ^[0-9]

Regular express to match `command--o1--o2--o3` [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a string like command--o1--o2--o3 ( command,o1,o2,o3 are arbitrary words)
And I want get [o1, o2, o3] though a Regular Expression(Not a array operation or other ways. JUST only use Regular Expression).
Is there any idea to accomplish this !?
If you're using JavaScript, and assuming you want all strings after a --, you may do
var things = str.split(/--/).slice(1)
If you just want to get the 2 characters words following --, then you may use
var things = str.match(/--\w\w/g).map(function(s){ return s.slice(2) })

Categories

Resources