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
"use strict"; | |
var _ = { | |
join: (array, separator = ',') => { | |
var newString = array.toString(); | |
if (separator) { | |
var replaced = newString.replace(",", separator); | |
} | |
console.log(replaced); | |
} |
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
module Luhn | |
def self.is_valid?(number) | |
# split the number into an array of its individual digits | |
numbers = number.to_s.split('').map { |x| x.to_i } | |
# set the index value for the starting number to be the second to last digit in numbers | |
digit_to_double = numbers.length - 2 | |
# until digit_to_double reaches the end of the array | |
while digit_to_double >= 0 | |
# double the number with an index of digit_to_double |
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
class LinkedListNode | |
attr_accessor :value, :next_node | |
def initialize(value, next_node=nil) | |
@value = value | |
@next_node = next_node | |
end | |
end | |
def print_values(list_node) |
NewerOlder