Created
November 3, 2011 14:20
-
-
Save sanemat/1336596 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bubbleSort = {} | |
bubbleSort.flag = false; | |
bubbleSort.values = [1, 3, 2, 5, 4]; | |
bubbleSort.bubbleSort = function(){ | |
do { | |
this.flag = false; | |
var count = this.values.length; | |
var k = 0; | |
for(var i = 0; i < count - 1 - k; ++i){ | |
if (this.values[i] > this.values[i + 1]) { | |
this.flag = true; | |
[this.values[i], this.values[i + 1]] = [this.values[i + 1], this.values[i]]; | |
} | |
} | |
++k; | |
} while (this.flag); | |
}; | |
describe('bubbleSort', function(){ | |
it('should return sorted value', function(){ | |
expect(bubbleSort.values).toEqual([1, 3, 2, 5, 4]); | |
bubbleSort.bubbleSort(); | |
expect(bubbleSort.values).toEqual([1, 2, 3, 4, 5]); | |
}); | |
}); |
I want to use "destructuring assignment", but I got fail.
https://gist.github.com/1336596/4570cd315b88b41ed360962928c3d4aaafab8dbf
Why?
$ ~/node_modules/jasmine-node/bin/jasmine-node BubbleSort.js The "sys" module is now called "util". It should have a similar interface. Started F bubbleSort it should return sorted value ReferenceError: Invalid left-hand side in assignment at Object.bubbleSort (/Users/sane/work/js-study/algrism-and-data/BubbleSort.js:12:9) at [object Object]. (/Users/sane/work/js-study/algrism-and-data/BubbleSort.js:21:16) Finished in 0.012 seconds 1 test, 2 assertions, 1 failure $ node --version v0.6.3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Finally, I soloved my problem.
https://gist.github.com/1336596/12da47b354b7f7c5975fd67b4c72e4c48e958b52
Thanks.