Giter VIP home page Giter VIP logo

wtfjs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wtfjs's Issues

Regexp: Not exactly reusable...

I think this is just WTF.

[jann@Jann-PC dnode-protocol master]$ node
> var regexp = /\+((?:\+)?[\w\-]+)*(?:\.v\d+\.\d+\.\d+)?(?:\.js)$/g;
> function f(){console.log(regexp.exec('/socket.io+websocket.v0.8.10.js') != null);}
> setInterval(f, 100)
{ ontimeout: [Function] }
> true
false
true
false
true
false
true
false

Unschareable URL

http://wtfjs.com/2013/08/07/Math.max()-behaviour isn't schareable on twitter. 😭

Fibonacci is so last year, let's go with Lucas numbers.

Made by hand, rather than using wtfjs, but I'm sure it's easy to redo:

function lucas(n) { for(_=++[+[]][+[]],__=++[_][+[]]<<++[_][+[]]<<++[_][+[]]<<_;__>+[];_=++[+[]][+[]]+(++[+[]][+[]]/_),__--);for(__=_;-++[+[]][+[]]+--n;_*=__);return(++[+[]][+[]]/++[++[+[]][+[]]][+[]]+_)|+[]; }

Computes the golden ratio φ by evaluating the continued fraction for the golden ratio over 64 iterations, then computes the Lucas number lucas(n) directly as round(φ^(n-1)).

(more detailed composition explained over at https://pomax.github.io/#gh-weblog-1418775170598)

Page does not load (400 error)

This page is in the index, but actually attempting to open it leads to a 400 error. Is it related to the parsing of the URL seeing "[]" as a trouble input and bailing out due to what it considered a security issue?

EDIT: The link on this issue is mangled and the right brackets are percent-encoded which leads to a 404 not found error. Perhaps move the page?

Date comparison

I'm surprised no one uncovered that here:

new Date(10) == new Date(10) // false
new Date(10) < new Date(11) // true
new Date(11) > new Date(12) // false
new Date(11) > new Date(10) // true

Two object instances are always unequal. But they decided to overload operator < and > for Date and not ==. This renders the whole thing useless.

2010 02 12 maths fun - one example applies to many lanugages

It is important to note that in this one https://wtfjs.com/wtfs/2010-02-12-maths-fun even the case where:

0.1 + 02 === 0.3 // false

is the same for Python:

0.1 + 0.2 == 0.3 // False

So this is not a quirk of just JS but it also stems to other languages like Python and it is not a problem of the language but more so an issue that stems from the way that computers store numbers (binary). I believe that this example should be removed because it is not specific to JS.

es5

var a = [1,2,3];
Array.prototype.isPrototypeOf(a); // true
var b = 123;
Number.prototype.isPrototypeOf(b); // false
var c = new Number(123);
Number.prototype.isPrototypeOf(b); // true
typeof b; //number
typeof c; //object
b == c; //true
b === c; //false
c += 1; //124
typeof c; //number

typeof null; //object

RSS broken

http://wtfjs.com/rss

This page contains the following errors:

error on line 19 at column 14: Opening and ending tag mismatch: code line 0 and p
Below is a rendering of the page up to the first error.

new Number()

var x = 12;
var y = 12;
x === y // true

var x = new Number(12);
var y = new Number(12);
x === y // false
x == y // false

var x = y = new Number(12);
x === y // true

While it might be useful to set two variables as references to the same Number instance object, the object instance does not have any method available to mutate it's internal primitive value, so this feature ended up only useful in confusing people.

Probably something inherited from Java?

Array.prototype.indexOf WTF or not empty array don't contain it element.

Not empty array don't contains it element:
var a = [,]; alert(a.indexOf(a[0]));

alert will return -1. The main point in this example is difference between uninitialized and undefined values.

The problem is in this:
a.length is 1. So array has some elements. But a[0] is undefined and a.indexOf(undefined) will return -1.

Undefined is the javascript primitive type. Uninitialized means the value that don't have any javascript type.

P.S. I'm trying to find why a[0] return undefined now for complete explanation.

typo

Hi again, I'm sorry but there are 3 typos in my last post "hexadecimal weirdness"

Can you put
"In JS you can represent numbers in hexadecimal, right?"
instead of
"In JS you an represent numbers in haxadecimal, right?"

and

alert(hex.toString(16)); // 0xFF5500
instead of
alert(hex.toString(16); // 0xFF5500

Thanks!

all your commas are belong to Array last WTF

The last WTF:

",,," == Array((null,'cool',false,NaN,4)); // true

can be explained in the following way:

  1. The expression (null,'cool',false,NaN,4) being evaluated first
  2. Comma "," operator executes both sides of expression and returns the result of the last one, so
 null, 'cool', false, NaN, 4 => 'cool', false, NaN, 4 => false, NaN, 4 => NaN, 4 => 4
  1. So the remaining expression is the same as one of the explained cases:
 ",,," == new Array(4); // true

So really, it's just some magic behind the comma operator.

Website issues

Great to see the site back up again—I'd like to report a few issues I've noticed while browsing the site.

Is this project dead?

Lots of pull requests which hasn't been merged and the website hasn't been updated since 2016

enhance.dev rework

Todo:

  • / currently redirects to /wtfs. That's not the current behavior
  • /wtfs works but /wtfs doesn't. That's not the current behavior
  • about and license page

Open questions

  • jQuery still needed? I can't find any place, where it is used
  • Should the design stay the same or be brought up to date?
  • Should shared/ logic be preserved?

Website down

Hi guys,
looks like the website is down?

The last time I tried it just showed "nginx correctly installed"?

It might be a good idea to set it up on github.io?

No recursive function in strict mode

[code=es:0]
"use strict";

var foo, bar, baz;

foo = function(bar){
if(bar === 0){
return(1);
}else if(bar < 0){
return(-1);
}else{
return(bar * arguments.callee(bar - 1));
}
}

foo(5);
[/code]

Does not work in strict mode, throws a type error.

Explanation for why-am-i-a-number

why am i a number by @jhnns:

Can someone tell me?

"Why am I a " + typeof + ""; // "Why am I a number"

Because in this context the (second) + character isn't an addition operator but a unary + operator.

It is used to cast values to a number. In this case the empty string is casted to the number 0, of which the type is (obviously) "number".

Remember about +new Date()? This +"" is just like that.

So wrapped in logical groups:

"Why am I a " + ( typeof ( +"" ) ); // "Why am I a number"

RSS is broken

You better fix your RSS feed, cause it's totally broken...

regards

Arary Comparison

http://wtfjs.com/2013/01/28/array-comparison
'Did you know that JavaScript can compare arrays using lexicographical ordering?'

With >, >=, <, <=, they're both converted to strings, and JavaScript will compare each character code in order. Note also,

[10, 2, 3] > [2, 2, 3] // false

Maintain this repository

Hello everybody,

This repository seems to be inactive for a quite long time. It has 13 open issues and 35 Pull Requests. That's why I create a new github organization to fork and maintain this repository.
Here is it: https://github.com/wthjs/wtfjs

If you want to maintain this repository, please let know by leaving comment on this issue.

Thanks.

true == 'true' is not true

The section "false isnt false" claims that:

true == 'true'     // true
false == 'false';  // false

But in fact the first line also resolves to false. Please correct it!

You may prefer to write that section like this:

false == '0';      // true
false == 'false';  // false

The Hungry Variable

Again some misunderstanding
There is a small difference between

/[/ + "javascript"[0] + '///'

and

/[/ + "javascript"[0] + '///'

Fix syntax highlighting

On at least some Markdown processors, the line containing "```" can contain the language, such as:

``` javascript
function code() {yield 5; return null;}
```

Could display as

function code() {yield 5; return null;}

This means that one potential solution to fixing the syntax highlighting is to simply add the "javascript" language specification on the initial "```" line. Please check whether it actually works for your posts already, or if some additional plugin to support the Javascript language is needed.

EDIT: This page already has that fix. You should try to install a syntax highlighting plugin to your Markdown install and check on this page, before making this change. Perhaps highlight.js?

EDIT 2: See this page for how to enable syntax highlighting with Marked.JS.

Posts Sorting Issue ...

Since readdir doesn't guarantee the order of returned filenames there are two missing calls to sort() in the code of post.js.

--- a/node-code-blog/post.js
+++ b/node-code-blog/post.js
@@ -25,3 +25,3 @@ Post.paginate = function(page) {
     fs.readdir(postsPath, function(err, files){
-        var posts = Post.all(files).reverse()
+        var posts = Post.all(files.sort().reverse())
         ,   count = 5
@@ -52,3 +52,3 @@ Post.rss = function(title, desc, domain) {
     s += 'http://' + domain + '/'; 
-    var posts = Post.all(fs.readdirSync(postsPath).reverse());
+    var posts = Post.all(fs.readdirSync(postsPath).sort().reverse());
     for (var i = 0; i < 5; i++) {        

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.