Skip to content

Instantly share code, notes, and snippets.

View Samuelachema's full-sized avatar

Samuel Achema Samuelachema

View GitHub Profile
@Samuelachema
Samuelachema / longest.js
Created August 14, 2018 00:27
Write a function called longest which will take a string of space separated words and will return the longest one
/*Write a function called longest which will take a string of space separated words and will return the longest one.
For example:
longest("This is Andela")
returns
"Andela"
and
longest("Brilliance is evenly distributed")
returns
@Samuelachema
Samuelachema / longest.js
Created August 14, 2018 00:27
Write a function called longest which will take a string of space separated words and will return the longest one
/*Write a function called longest which will take a string of space separated words and will return the longest one.
For example:
longest("This is Andela")
returns
"Andela"
and
longest("Brilliance is evenly distributed")
returns
@Samuelachema
Samuelachema / power.js
Created August 14, 2018 00:21
Write a function named power that accepts two arguments, a and b and calculates a raised to the power b
/*Write a function named power that accepts two arguments, a and b and calculates a raised to the power b.
Example
power(2, 3) => 8
Note: Don't use
2 ** 3
and don't use
@Samuelachema
Samuelachema / mysort.js
Created August 14, 2018 00:18
Write a mySort function which takes in an array integers, and should return an array of the inputed integers sorted such that the odd numbers come first and even numbers come last.
/*
JavaScript
Write a mySort function which takes in an array integers, and should return an array of the inputed integers sorted such that the odd numbers come first and even numbers come last.
For exampl1e:
mySort( [90, 45, 66, 'bye', 100.5] )
should return
[45, 66, 90, 100]
@Samuelachema
Samuelachema / removeduplicates.js
Created August 14, 2018 00:14
Write a function which will take one string argument containing characters between a-z, and should remove all repeated characters (duplicates) in the string.
/*
Write a function which will take one string argument containing characters between a-z, and should remove all repeated characters (duplicates) in the string.
Python
The function should be called remove_duplicates and should return a tuple with two values:
A new string with only unique, sorted characters.
The total number of duplicates dropped.
For example:
@Samuelachema
Samuelachema / shoppingcart.js
Created August 14, 2018 00:08
Create a class called ShoppingCart. Create a constructor that has no arguments and sets the total attribute to zero, and initializes an empty dict attribute named items. Create a method addItem that requires itemName, quantity and price arguments. This method should add the cost of the added items to the current value of total...
/*
Create a class called ShoppingCart. Create a constructor that has no arguments and sets the total attribute to zero, and initializes an empty dict attribute named items. Create a method addItem that requires itemName, quantity and price arguments. This method should add the cost of the added items to the current value of total. It should also add an entry to the items dict such that the key is the itemName and the value is the quantity of the item. Create a method removeItem that requires similar arguments as add_item. It should remove items that have been added to the shopping cart and are not required. This method should deduct the cost of these items from the current total and also update the items dict accordingly. If the quantity of items to be removed exceeds current quantity in cart, assume that all entries of that item are to be removed. Create a method checkout that takes in cashPaid and returns the value of balance from the payment. If cashPaid is not enough to cover the total, return Cash pa
@Samuelachema
Samuelachema / isogram.js
Created August 14, 2018 00:01
Create a method isIsogram that takes one argument, a word to test if it's an isogram. This method should return a boolean indicating whether it is an isogram. If the argument supplied is an empty string, return False.
function isIsogram(word){
if (word !== undefined){
const wordArr = word;
if(word === ""){
return false;
}
for (let i = 0; i < wordArr.length; i++) {
for (let j = 0; j < wordArr.length; j++) {
if(i!=j){
if (wordArr[i] == wordArr[j]) {