* Creator of bechdel.io
const arr = [
'accessing', 'an', 'array',
'element', 'takes', 'constant', 'time'
];
const index = arr[4];
const isEven = (num) => {
return num % 2;
}
// Function to recursively print the right half of a string
const splitRight = (str) => {
let length = str.length;
// Helper function
const help = (index) => {
// Recursive Case: Print right half
if(index < length){
// Prints characters from index
// until the end of the array
console.log(str.substring(index, length));
// Recursive Call: call help on right half
help(Math.ceil((length + index)/2));
}
// Base Case: Do Nothing
}
help(0);
}
const sumOfArr = (arr) => {
var sum = 0;
for (let i = 0; i < arr.length; i++){
sum += arr[i];
}
return sum;
}
def mergesort(list)
return list if list.size <= 1
mid = list.size / 2
left = list[0, mid]
right = list[mid, list.size]
merge(mergesort(left), mergesort(right))
end
def merge(left, right)
sorted = []
until left.empty? or right.empty?
if left.first <= right.first
sorted << left.shift
else
sorted << right.shift
end
end
sorted.concat(left).concat(right)
end
const makeGrid = () => {
const grid = document.createElement('table');
grid.className = 'grid';
for (let r = 0; r < this._rows; ++r) {
let tr = grid.appendChild(document.createElement('tr'));
for (let c = 0; c < this._cols; ++c) {
let cell = tr.appendChild(document.createElement('td'));
cell.id = "grid" + i++
}
}
}
let size = 5;
const fork = (i) => {
if( i < size ){
fork(i+1);
fork(i+1);
}
}
fork(0);
def bubble_sort(list)
for i in 0..(list.size - 1)
for j in 0..(list.size - i - 2)
if (list[j + 1] <=> list[j]) == -1
list[j], list[j + 1] = list[j + 1], list[j]
end
end
end
return list
end
def factorial(n)
if n.zero?
return 1
else
return n * factorial(n - 1)
end
end
def palindrome?(input)
stack = []
output = ""
input.each_char do |x|
stack.push x
end
while not stack.empty?
output << stack.pop
end
return (output == input)
end
const loop = (N) => {
if(N < 0) {
return N;
}
return loop(N-1) + loop(N-2) + loop(N-3);
}
let size = 5;
function fork(i){
if(i <= size){
for(let j = 0; j < i; j++){
fork(i+1);
}
}
}
fork(1);
Please fill out this feedback form:
https://goo.gl/forms/Hsn6oonjyIl1yxCm1