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
/* | |
The input is an array of numbers, e.g. arr = [1, -2, 3, 4, -9, 6]. | |
The task is: find the contiguous subarray of arr with the maximal sum of items. | |
Write the function getMaxSubSum(arr) that will find return that sum. | |
For instance: | |
getMaxSubSum([-1, 2, 3, -9]) = 5 (the sum of highlighted items) |
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
/* | |
Write the function sumInput() that: | |
Asks the user for values using prompt and stores the values in the array. | |
Finishes asking when the user enters a non-numeric value, an empty string, or presses “Cancel”. | |
Calculates and returns the sum of array items. | |
P.S. A zero 0 is a valid number, please don’t stop the input on zero. | |
*/ | |
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
/*Eloquent JS | |
FizzBuzz | |
Write a program that uses console.log to print all the numbers from 1 | |
to 100, with two exceptions. For numbers divisible by 3, print "Fizz" | |
instead of the number, and for numbers divisible by 5 (and not 3), print | |
"Buzz" instead. | |
When you have that working, modify your program to print "FizzBuzz", | |
for numbers that are divisible by both 3 and 5 (and still print "Fizz" or | |
"Buzz" for numbers divisible by only one of those). |
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
/* | |
Chess board | |
Write a program that creates a string that represents an 8×8 grid, using | |
newline characters to separate lines. At each position of the grid there | |
is either a space or a “#” character. The characters should form a chess | |
board. | |
Passing this string to console.log should show something like this: | |
# # # # | |
# # # # | |
# # # # |
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
/* | |
Looping a triangle (eloquent Javascript ex) | |
Write a loop that makes seven calls to console.log to output the following | |
triangle: | |
# | |
## | |
### | |
#### | |
##### | |
###### |
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
/* | |
Given an array of integers, find the pair of adjacent elements that has the largest product and return that product. | |
Example | |
For inputArray = [3, 6, -2, -5, 7, 3], the output should be | |
adjacentElementsProduct(inputArray) = 21. | |
7 and 3 produce the largest product. |
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
/*Given a year, return the century it is in. The first century spans from the year 1 up to and including the year 100, the second - from the year 101 up to and including the year 200, etc. | |
Example | |
For year = 1905, the output should be | |
centuryFromYear(year) = 20; | |
For year = 1700, the output should be | |
centuryFromYear(year) = 17. | |
The solution i tried is below |
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
"""Try displaying a photo of yourself on the canvas using tkinter. | |
Make sure it’s a GIF image! Can you make it move across the | |
screen?""" | |
import time | |
from tkinter import * | |
tk = Tk() | |
w = 500 | |
h = 500 | |
canvas = Canvas(tk, width=w, height=h) |
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
""" | |
Make a triangle move across the screen to the right, | |
then down, then back to the left, and then back to its starting | |
position. Using tkinter | |
""" | |
import time | |
from tkinter import * | |
tk = Tk() | |
canvas = Canvas(tk, width=400, height=400) |
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
""" | |
Create a program that asks the user to enter | |
their name and their age. Print out a message addressed to them that tells them the year | |
that they will turn 100 years old. | |
Extras: | |
Add on to the previous program by asking the user for another number and printing out | |
that many copies of the previous message. (Hint: order of operations exists in Python) | |
Print out that many copies of the previous message on separate lines. (Hint: the string |
NewerOlder