This file contains hidden or 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
| def checkMagazine(magazine, note) | |
| mag_hash = {} | |
| magazine.each do |word| | |
| mag_hash[word] = mag_hash[word] ? mag_hash[word] + 1 : 1 | |
| end | |
| answer ='Yes' | |
| note.each do |word| | |
| if !mag_hash[word] || mag_hash[word] <= 0 | |
| answer = 'No' | |
| else |
This file contains hidden or 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
| def checkMagazine(magazine, note) | |
| check = note.reduce(true) do |memo,word| | |
| memo = (magazine.count(word) >= note.count(word)) ? memo : false | |
| end | |
| puts check ? "Yes" : "No" | |
| end |
This file contains hidden or 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
| #!/bin/ruby | |
| require 'json' | |
| require 'stringio' | |
| # Complete the checkMagazine function below. | |
| def checkMagazine(magazine, note) | |
| end |
This file contains hidden or 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
| handleKeep = () => { | |
| const formData = new FormData(); | |
| formData.append("camera", this.state.currentPhoto); | |
| // Use an appropriate url | |
| fetch(`${baseURL}/photo/${this.props.profile.id}`, { | |
| method: "PATCH", | |
| body: formData | |
| }) | |
| .then(res => res.json()) |
This file contains hidden or 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
| handlePhoto = dataUri => { | |
| this.setState({ currentPhoto: dataUri }); | |
| ]}; |
This file contains hidden or 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
| uploadPhoto = () => { | |
| const formData = new FormData(); | |
| formData.append("file", this.state.newPhoto); | |
| // configure your fetch url appropriately | |
| fetch(`${baseURL}/photo/${this.props.profile.id}`, { | |
| method: "PATCH", | |
| body: formData | |
| }) | |
| .then(res => res.json()) |
This file contains hidden or 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
| handleImageChange = e => { | |
| if (e.target.files[0]) this.setState({ newPhoto: e.target.files[0] }); | |
| }; |
This file contains hidden or 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
| def update | |
| if params[:file] | |
| # The data is a file upload coming from <input type="file" /> | |
| @profile.avatar.attach(params[:file]) | |
| # Generate a url for easy display on the front end | |
| photo = url_for(@profile.avatar) | |
| elsif params[:camera] | |
| # The data is Base64 and coming from the camera. | |
| # Use that data to create a file for active storage. | |
| blob = ActiveStorage::Blob.create_after_upload!( |
This file contains hidden or 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
| value = moment( | |
| e.target.value, | |
| moment.HTML5_FMT.DATETIME_LOCAL | |
| ).format(); |
This file contains hidden or 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
| <input | |
| className="input" | |
| name={props.field} | |
| type="datetime-local" | |
| value={moment(props.value).format( | |
| moment.HTML5_FMT.DATETIME_LOCAL | |
| )} | |
| onChange={this.handleChange} | |
| /> |