Skip to content

Instantly share code, notes, and snippets.

View morisasy's full-sized avatar

Risasi morisasy

View GitHub Profile
@morisasy
morisasy / index.html
Created August 26, 2016 15:45
JuliusNyererekambarage
<div class = "containter-fluid">
<div class ="header">
<div class = "well">
<h1 class = "text-primary text-center">Dr.Julius Kambarage Nyerere</h1>
<p class = "text-center">Tanzanian statesman and president Julius Kambarage was premier when Tanganyika was granted internal self-government, and was made president on independence</p>
</div>
</div>
<div class = "containter">
<div class = "well">
<img class="img-responsive" src="https://media1.britannica.com/eb-media/77/160377-004-ECB7BCBD.jpg" alt="Julius Nyerere" width = "100%" height = "auto">
//Write a function called "findMinLengthOfThreeWords".
//Given 3 words, "findMinLengthOfThreeWords" returns the length of the shortest word.
function findMinLengthOfThreeWords(word1, word2, word3) {
if (word1.length < word2.length) {
if (word1.length <word3.length) {
return word1.length;
}else {
@morisasy
morisasy / getElementsThatEqual10AtProperty
Created July 12, 2017 09:02
get elements that equal to 10th at property
Write a function called "getElementsThatEqual10AtProperty".
Given an object and a key, "getElementsThatEqual10AtProperty" returns an array containing all the elements of the array located at the given key that are equal to ten.
Notes:
* If the array is empty, it should return an empty array.
* If the array contains no elements equal to 10, it should return an empty array.
* If the property at the given key is not an array, it should return an empty array.
* If there is no property at the key, it should return an empty array.
function getElementsThatEqual10AtProperty(obj, key) {
@morisasy
morisasy / function select
Created July 12, 2017 10:15
selectfunction
Write a function called "select".
Given an array and an object, "select" returns a new object whose properties are those in the given object AND whose keys are present in the given array.
Notes:
* If keys are present in the given array, but are not in the given object, it should ignore them.
* It does not modify the passed in object.
function select(arr, obj) {
// create an empty obj
var output = {};
@morisasy
morisasy / removeElement
Created July 12, 2017 13:42
Write a function called "removeElement". Given an array of elements, and a "discarder" parameter, "removeElement" returns an array containing the items in the given array that do not match the "discarder" parameter. Notes: * If all the elements match, it should return an empty array. * If an empty array is passed in, it should return an empty ar…
.
Given an array of elements, and a "discarder" parameter, "removeElement" returns an array containing the items in the given array that do not match the "discarder" parameter.
Notes:
* If all the elements match, it should return an empty array.
* If an empty array is passed in, it should return an empty array.
function removeElement(array, discarder) {
@morisasy
morisasy / getFirstElementOfProperty
Last active July 12, 2017 14:14
Write a function called "getFirstElementOfProperty". Given an object and a key, "getFirstElementOfProperty" returns the first element of the array located at the given key.
Notes:
* If the array is empty, it should return undefined.
* If the property at the given key is not an array, it should return undefined.
* If there is no property at the key, it should return undefined.
function getFirstElementOfProperty(obj, key) {
// your code here
if ( Array.isArray( obj[key] ) === false ){
return undefined;
}else if ( obj[key][0] === undefined){
return undefined;
@morisasy
morisasy / getNthElementOfProperty
Created July 12, 2017 14:18
Given an object and a key, write a function "getNthElementOfProperty" returns the nth element of an array located at the given key.
Notes:
* If the array is empty, it should return undefined.
* If n is out of range, it should return undefined.
* If the property at the given key is not an array, it should return undefined.
* If there is no property at the key, it should return undefined.
@morisasy
morisasy / getLastElementOfProperty
Created July 12, 2017 14:22
Given an object and a key, write a function "getLastElementOfProperty" returns the last element of an array located at the given key.
Notes:
* If the array is empty, it should return undefined.
* if the property at the given key is not an array, it should return undefined.
* If there is no property at the key, it should return undefined.
function getLastElementOfProperty(obj, key) {
@morisasy
morisasy / keep
Last active July 12, 2017 17:13
Given an array and a keeper element, create a function "keep" returns an array containing the items that match the given keeper element.
Notes:
* If no elements match, "keep" should return an empty array.
function keep(array, keeper) {
if(Array.isArray(array) === false){
return null;
}
return array.filter(function(value) {
return value == keeper;
@morisasy
morisasy / getOddLengthWordsAtProperty
Created July 12, 2017 18:00
Given an object and a key, create a function "getOddLengthWordsAtProperty" returns an array containing all the odd length word elements of the array located at the given key.
Notes:
* If the array is empty, it should return an empty array.
* If it contains no odd length elements, it should return an empty array.
* If the property at the given key is not an array, it should return an empty array.
* If there is no property at the given key, it should return an empty array.
function getOddLengthWordsAtProperty(obj, key) {
// your code here