Haskell, Ruby, Python, Nodejs如何把一个句子的词语倒序

Haskell:

  unwords . reverse . words $ sentence

Ruby:

  sentence.split.reverse.join ' '

Python:

  " ".join(reversed(sentence.split()))

Node.js:

var EventEmitter = require('events').EventEmitter;

var emitter = new EventEmitter();

emitter.on('got sentence', function(sentence) {
    emitter.emit('split sentense', sentence.split(' '));
});
emitter.on('split sentense', function(splitted) {
    emitter.emit('reversed', splitted.reverse());
});
emitter.on('reversed', function(reversed) {
    emitter.emit('joined', reversed.join(' '));
});
emitter.on('joined', function(sentence) {
    console.log(sentence);
    emitter.emit('got sentence', sentence);
});

emitter.emit('got sentence', 'hello world');

Nodejs胜出。谁不服就是不客观。

via

Comments