mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-15 01:38:13 -05:00
This was done by first checking all files in the repository root by hand, and
then by doing the following:
$ npm i get-stdin@4
$ cat clean.coffee
fs = require 'fs'
stdin = require 'get-stdin'
stdin (text) ->
for file in text.trim().split('\n')
contents = fs.readFileSync file
.toString().replace /\s*$/, '\n'
fs.writeFileSync file, contents
return
$ ls !(node_modules)/**/*.coffee | coffee clean.coffee
24 lines
600 B
CoffeeScript
24 lines
600 B
CoffeeScript
# An in-place selection sort.
|
|
selection_sort = (list) ->
|
|
len = list.length
|
|
|
|
# For each item in the list.
|
|
for i in [0...len]
|
|
|
|
# Set the minimum to this position.
|
|
min = i
|
|
|
|
# Check the rest of the array to see if anything is smaller.
|
|
min = k for v, k in list[i+1...] when v < list[min]
|
|
|
|
# Swap if a smaller item has been found.
|
|
[list[i], list[min]] = [list[min], list[i]] if i isnt min
|
|
|
|
# The list is now sorted.
|
|
list
|
|
|
|
|
|
# Test the function.
|
|
console.log selection_sort([3, 2, 1]).join(' ') is '1 2 3'
|
|
console.log selection_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9'
|