-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
编程基础练习簿——作业 #100
Open
ghost
wants to merge
38
commits into
growthschool:master
Choose a base branch
from
unknown repository
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
编程基础练习簿——作业 #100
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
ef24bab
hello
23d367c
variable
401a3f3
triangle
48f75e3
pizzas
66fbc90
bmi
b6b57c8
integer-positive
28ab468
abcde
9ade712
find-max
f356799
function
78582c7
10-function
8c0696c
prime
4c9985e
guess-number
03ca433
array-sum
1d4dbfc
seven
26d6f8c
seven
2b912dc
sum-even
9fd163a
sum-even
5127362
nn
f3c4646
prime
8b13984
guess-number
73e9edd
array-stats
4d2c462
square
b477998
filter
6c224c1
sorting
fb1943c
selection-sort
c359ae6
missing
16f4364
hash-max
2b73cca
hash-max
ebdd553
hash-even
b15b64a
hash-even
2aeb178
hash-count
0c0f00b
hash-filter
668dc80
hash-filter
3fe75be
hash-filter
1f23ced
class
8f5161a
word-count
22a02d7
todos
e83d1b1
filter
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
# 给定一阵列内含数字,输出另一个数组只包含偶数 | ||
|
||
|
||
# | ||
# def filter_even(arr) | ||
# arr = [7, 68, 42, 46, 9, 91, 77, 46, 86, 1] | ||
# | ||
# end | ||
|
||
|
||
arr = [7, 68, 42, 46, 9, 91, 77, 46, 86, 1] | ||
a = [] | ||
|
||
arr.each do |i| | ||
if i % 2 == 0 | ||
puts a.push(i).to_s | ||
puts i # 这部分不知道怎么输出数组了? | ||
end | ||
end | ||
|
||
|
||
# puts arr.push(x).to_s | ||
# | ||
|
||
# puts filter_even(arr).to_s # 应该是 [68, 42, 46, 46, 86] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
# 请打开 wordcount.txt,计算每个单字出现的次数 | ||
|
||
|
||
doc = File.read("wordcount.txt") | ||
|
||
frequency1 = Hash.new(0) | ||
doc.each_char { |chr| frequency1[chr.downcase] +=1 } | ||
|
||
puts "Character: " | ||
frequency1.sort_by { |_key, value| value}.each do |key, value| | ||
puts "#{key} : #{value}" | ||
end | ||
|
||
puts "-------" | ||
|
||
frequency2 = Hash.new(0) | ||
words = doc.to_s.split(" ") | ||
words.each { |word| frequency2[word.downcase] +=1 } | ||
|
||
puts "words: " | ||
frequency2.sort_by {|_key, value| value}.each do |key, value| | ||
puts "#{key} : #{value}" | ||
end | ||
|
||
# ... |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
words = doc.to_s.split 我去掉(“”)后,才会出现单词,要不然出现的和上面一样,是字母。