Initial Commit
This commit is contained in:
		
							parent
							
								
									3ee040a525
								
							
						
					
					
						commit
						5767e909a2
					
				| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
const helloWorld = function() {
 | 
			
		||||
  return ''
 | 
			
		||||
  return 'Hello, World!'
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
module.exports = helloWorld;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,26 @@
 | 
			
		|||
const repeatString = function() {
 | 
			
		||||
const repeatString = function(inString,repeat) {
 | 
			
		||||
    var newString = "";
 | 
			
		||||
    // switch (repeat) {
 | 
			
		||||
    //     case repeat=0: return "";
 | 
			
		||||
    //     case repeat<0: return "ERROR";
 | 
			
		||||
    //     default:
 | 
			
		||||
        // for (i=1; i <= repeat; i++) {
 | 
			
		||||
        //     newString += string;
 | 
			
		||||
        // }
 | 
			
		||||
        // return newString;
 | 
			
		||||
    // }
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
    if (repeat > 0) {
 | 
			
		||||
        for ( i = 1 ; i <= repeat ; i++) {
 | 
			
		||||
            newString += inString;
 | 
			
		||||
        }
 | 
			
		||||
        return newString;
 | 
			
		||||
    } else if (repeat < 0) {
 | 
			
		||||
        return "ERROR";
 | 
			
		||||
    } else {
 | 
			
		||||
        return "";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Do not edit below this line
 | 
			
		||||
module.exports = repeatString;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,19 +4,19 @@ describe('repeatString', () => {
 | 
			
		|||
  test('repeats the string', () => {
 | 
			
		||||
    expect(repeatString('hey', 3)).toEqual('heyheyhey');
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('repeats the string many times', () => {
 | 
			
		||||
  test('repeats the string many times', () => {
 | 
			
		||||
    expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('repeats the string 1 times', () => {
 | 
			
		||||
  test('repeats the string 1 times', () => {
 | 
			
		||||
    expect(repeatString('hey', 1)).toEqual('hey');
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('repeats the string 0 times', () => {
 | 
			
		||||
  test('repeats the string 0 times', () => {
 | 
			
		||||
    expect(repeatString('hey', 0)).toEqual('');
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('returns ERROR with negative numbers', () => {
 | 
			
		||||
  test('returns ERROR with negative numbers', () => {
 | 
			
		||||
    expect(repeatString('hey', -1)).toEqual('ERROR');
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('repeats the string a random amount of times', function () {
 | 
			
		||||
  test('repeats the string a random amount of times', function () {
 | 
			
		||||
    /*The number is generated by using Math.random to get a value from between
 | 
			
		||||
    0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it 
 | 
			
		||||
    equals a number between 0 to 999 (this number will change everytime you run
 | 
			
		||||
| 
						 | 
				
			
			@ -31,7 +31,7 @@ describe('repeatString', () => {
 | 
			
		|||
    was randomaly generated. */
 | 
			
		||||
    expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('works with blank strings', () => {
 | 
			
		||||
  test('works with blank strings', () => {
 | 
			
		||||
    expect(repeatString('', 10)).toEqual('');
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,10 @@
 | 
			
		|||
const reverseString = function(str) {
 | 
			
		||||
 | 
			
		||||
    const temp = str.split('');
 | 
			
		||||
    var newString = ''
 | 
			
		||||
    for (i=1; i <= str.length; i++) {
 | 
			
		||||
        newString += temp[str.length-i]
 | 
			
		||||
    }
 | 
			
		||||
    return newString
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Do not edit below this line
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,14 +5,14 @@ describe('reverseString', () => {
 | 
			
		|||
    expect(reverseString('hello')).toEqual('olleh');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test.skip('reverses multiple words', () => {
 | 
			
		||||
  test('reverses multiple words', () => {
 | 
			
		||||
    expect(reverseString('hello there')).toEqual('ereht olleh')
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  test.skip('works with numbers and punctuation', () => {
 | 
			
		||||
  test('works with numbers and punctuation', () => {
 | 
			
		||||
    expect(reverseString('123! abc!')).toEqual('!cba !321')
 | 
			
		||||
  })
 | 
			
		||||
  test.skip('works with blank strings', () => {
 | 
			
		||||
  test('works with blank strings', () => {
 | 
			
		||||
    expect(reverseString('')).toEqual('')
 | 
			
		||||
  })
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,12 @@
 | 
			
		|||
const removeFromArray = function() {
 | 
			
		||||
 | 
			
		||||
const removeFromArray = ( inArray, ...theFilters ) => {
 | 
			
		||||
    // Create a local mutable copy of input Array
 | 
			
		||||
    var filterArray = inArray;
 | 
			
		||||
    //Cycle through elements of theFilters
 | 
			
		||||
    for (i = 1; i <= theFilters.length ; i++) {
 | 
			
		||||
        //Filters filterArray by each sub-element of theFilters element
 | 
			
		||||
        filterArray = filterArray.filter(item => item !== theFilters[i-1]); 
 | 
			
		||||
    }
 | 
			
		||||
    return filterArray;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Do not edit below this line
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,23 @@
 | 
			
		|||
const sumAll = function() {
 | 
			
		||||
const sumAll = function(...theArgs) {
 | 
			
		||||
    /* - make sure you pay attention to the function parameters
 | 
			
		||||
    Test that the inputs are +ve integers
 | 
			
		||||
    */
 | 
			
		||||
    const result = theArgs.every(e => Number.isInteger(e) && e > 0);
 | 
			
		||||
    //Intialize summation variable
 | 
			
		||||
    var finalSum = null;
 | 
			
		||||
    if(result) {
 | 
			
		||||
        // const inMin = ;
 | 
			
		||||
        // const inMax = ;
 | 
			
		||||
        for (i = Math.min(...theArgs); i <= Math.max(...theArgs); i++) {
 | 
			
		||||
            // - on each iteration add the number to the sum
 | 
			
		||||
            finalSum += i;
 | 
			
		||||
        }
 | 
			
		||||
        // - return the sum after finishing the loop
 | 
			
		||||
        return finalSum
 | 
			
		||||
    } else {
 | 
			
		||||
        return 'ERROR';
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,19 +4,19 @@ describe('sumAll', () => {
 | 
			
		|||
  test('sums numbers within the range', () => {
 | 
			
		||||
    expect(sumAll(1, 4)).toEqual(10);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('works with large numbers', () => {
 | 
			
		||||
  test('works with large numbers', () => {
 | 
			
		||||
    expect(sumAll(1, 4000)).toEqual(8002000);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('works with larger number first', () => {
 | 
			
		||||
  test('works with larger number first', () => {
 | 
			
		||||
    expect(sumAll(123, 1)).toEqual(7626);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('returns ERROR with negative numbers', () => {
 | 
			
		||||
  test('returns ERROR with negative numbers', () => {
 | 
			
		||||
    expect(sumAll(-10, 4)).toEqual('ERROR');
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('returns ERROR with non-number parameters', () => {
 | 
			
		||||
  test('returns ERROR with non-number parameters', () => {
 | 
			
		||||
    expect(sumAll(10, "90")).toEqual('ERROR');
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('returns ERROR with non-number parameters', () => {
 | 
			
		||||
  test('returns ERROR with non-number parameters', () => {
 | 
			
		||||
    expect(sumAll(10, [90, 1])).toEqual('ERROR');
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,25 @@
 | 
			
		|||
const leapYears = function() {
 | 
			
		||||
 | 
			
		||||
const leapYears = function(...theArgs) {
 | 
			
		||||
    // > Leap years are years divisible by four (like 1984 and 2004). 
 | 
			
		||||
    // However, years divisible by 100 are not leap years (such as 1800 and 1900) 
 | 
			
		||||
    // unless they are divisible by 400 (like 1600 and 2000, which were in fact leap years). 
 | 
			
		||||
    
 | 
			
		||||
    //Initialize result variable
 | 
			
		||||
    var result = null
 | 
			
		||||
    //Test to ensure input is valid year
 | 
			
		||||
    const valid = theArgs.every(e => Number.isInteger(e) && e > 0);
 | 
			
		||||
    //Initialize a year variable
 | 
			
		||||
    const year = Math.floor(theArgs[0]);
 | 
			
		||||
    // Check year/4 and fail if not eligible
 | 
			
		||||
    if (valid && (year % 4) == 0) {
 | 
			
		||||
        result =  true
 | 
			
		||||
        // check if century and not @ 400 interval
 | 
			
		||||
        if ((year % 100) == 0 && (year % 400) != 0) {
 | 
			
		||||
          result = false;
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        result =  false
 | 
			
		||||
    }
 | 
			
		||||
return result
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Do not edit below this line
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,19 +4,19 @@ describe('leapYears', () => {
 | 
			
		|||
  test('works with non century years', () => {
 | 
			
		||||
    expect(leapYears(1996)).toBe(true);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('works with non century years', () => {
 | 
			
		||||
  test('works with non century years', () => {
 | 
			
		||||
    expect(leapYears(1997)).toBe(false);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('works with ridiculously futuristic non century years', () => {
 | 
			
		||||
  test('works with ridiculously futuristic non century years', () => {
 | 
			
		||||
    expect(leapYears(34992)).toBe(true);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('works with century years', () => {
 | 
			
		||||
  test('works with century years', () => {
 | 
			
		||||
    expect(leapYears(1900)).toBe(false);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('works with century years', () => {
 | 
			
		||||
  test('works with century years', () => {
 | 
			
		||||
    expect(leapYears(1600)).toBe(true);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('works with century years', () => {
 | 
			
		||||
  test('works with century years', () => {
 | 
			
		||||
    expect(leapYears(700)).toBe(false);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,24 @@
 | 
			
		|||
const ftoc = function() {
 | 
			
		||||
// Write two functions that convert temperatures from Fahrenheit to Celsius, and vice versa:
 | 
			
		||||
// ```
 | 
			
		||||
// ftoc(32) // fahrenheit to celsius, should return 0
 | 
			
		||||
 | 
			
		||||
// ctof(0) // celsius to fahrenheit, should return 32
 | 
			
		||||
// ```
 | 
			
		||||
 | 
			
		||||
// Because we are human, 
 | 
			
		||||
// we want the result temperature to be rounded to one decimal place: 
 | 
			
		||||
// i.e., `ftoc(100)` should return `37.8` and not `37.77777777777778`.
 | 
			
		||||
 | 
			
		||||
const ftoc = function(degF) {
 | 
			
		||||
  var degC =  (degF - 32) * (5/9);
 | 
			
		||||
  degC = Number.degC.toFixed(1);
 | 
			
		||||
  return degC;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const ctof = function() {
 | 
			
		||||
 | 
			
		||||
const ctof = function(degC) {
 | 
			
		||||
  var degF = (degC*9/5) + 32;
 | 
			
		||||
  degF = Number.degF.toFixed(1);
 | 
			
		||||
  return degF;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Do not edit below this line
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,22 +4,22 @@ describe('ftoc', () => {
 | 
			
		|||
  test('works', () => {
 | 
			
		||||
    expect(ftoc(32)).toEqual(0);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('rounds to 1 decimal', () => {
 | 
			
		||||
  test('rounds to 1 decimal', () => {
 | 
			
		||||
    expect(ftoc(100)).toEqual(37.8);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('works with negatives', () => {
 | 
			
		||||
  test('works with negatives', () => {
 | 
			
		||||
    expect(ftoc(-100)).toEqual(-73.3);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe('ctof', () => {
 | 
			
		||||
  test.skip('works', () => {
 | 
			
		||||
  test('works', () => {
 | 
			
		||||
    expect(ctof(0)).toEqual(32);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('rounds to 1 decimal', () => {
 | 
			
		||||
  test('rounds to 1 decimal', () => {
 | 
			
		||||
    expect(ctof(73.2)).toEqual(163.8);
 | 
			
		||||
  });
 | 
			
		||||
  test.skip('works with negatives', () => {
 | 
			
		||||
  test('works with negatives', () => {
 | 
			
		||||
    expect(ctof(-10)).toEqual(14);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1253,9 +1253,9 @@
 | 
			
		|||
      "dev": true
 | 
			
		||||
    },
 | 
			
		||||
    "caniuse-lite": {
 | 
			
		||||
      "version": "1.0.30001223",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001223.tgz",
 | 
			
		||||
      "integrity": "sha512-k/RYs6zc/fjbxTjaWZemeSmOjO0JJV+KguOBA3NwPup8uzxM1cMhR2BD9XmO86GuqaqTCO8CgkgH9Rz//vdDiA==",
 | 
			
		||||
      "version": "1.0.30001286",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001286.tgz",
 | 
			
		||||
      "integrity": "sha512-zaEMRH6xg8ESMi2eQ3R4eZ5qw/hJiVsO/HlLwniIwErij0JDr9P+8V4dtx1l+kLq6j3yy8l8W4fst1lBnat5wQ==",
 | 
			
		||||
      "dev": true
 | 
			
		||||
    },
 | 
			
		||||
    "capture-exit": {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,9 +26,10 @@
 | 
			
		|||
  "eslintConfig": {
 | 
			
		||||
    "root": true
 | 
			
		||||
  },
 | 
			
		||||
   "jest": {
 | 
			
		||||
  "jest": {
 | 
			
		||||
    "testPathIgnorePatterns": [
 | 
			
		||||
      "generator-exercise/"
 | 
			
		||||
    ]
 | 
			
		||||
  }
 | 
			
		||||
  },
 | 
			
		||||
  "dependencies": {}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue