Skip to content

Instantly share code, notes, and snippets.

View anthonygharvey's full-sized avatar

Anthony Harvey anthonygharvey

View GitHub Profile
reverse('hello') === 'olleh'
reverse('world!') === '!dlrow'
reverse('JavaScript') === 'tpircSavaJ'
function reverse(string) {
let answer = string.split('') // step 1
answer.reverse() // step 2
answer = answer.join('') // step 3
return answer //step 4
}
function reverse(string) {
return string.split('').reverse().join('')
}
function reverse(string) {
return [...string].reverse().join('')
}
function reverse(string) {
let reversed = '' // step 1
for(let char of string) { // step 2
reversed = char + reversed; // step 3
}
return reversed; // step 4
}
function reverse(string) {
return string.split('').reverse().join('')
}
reverse('JS is fun! 😄')
// => �� !nuf si SJ
function reverse(string) {
return Array.from(str).reverse().join("")
}
reverse('JS is fun! 😄')
// => 😄 !nuf si SJ
@anthonygharvey
anthonygharvey / if_statement_v1.rb
Last active March 6, 2019 01:19
a `Movie` class with several attributes and functionality to only update a movie’s title if the `in_progress` attribute is `true`
class Movie
attr_accessor :in_progress
attr_reader :title, :length, :budget
def title=(new_title)
if @in_progress
@title = new_title
end
end
end
class Movie
attr_accessor :finalized
attr_reader :title, :length, :budget
def title=(new_title)
if not @finalized
@title = new_title
end
end
end
class Movie
attr_accessor :finalized
attr_reader :title, :length, :budget
def title=(new_title)
unless @finalized
@title = new_title
end
end
end