Skip to content

Instantly share code, notes, and snippets.

View sandrabosk's full-sized avatar
👩‍💻
Always a student, never a master. Have to keep moving forward. ~C.Hall

Aleksandra Bošković sandrabosk

👩‍💻
Always a student, never a master. Have to keep moving forward. ~C.Hall
  • Ironhack
View GitHub Profile

PTWD-MIA-OCT2019/MAY2020

// 1: Calculate the total population in the given array (`data`):
const data = [
{
country: 'USA',
pop: 340
},
{
country: 'France',
pop: 133

Challenge 1:

Given an array of numbers, filter out the numbers that are not even, and are less than 100.

const numbers = [1, 60, 112, 123, 100, 99, 73];

const newArray = numbers.filter(number => {
  return number % 2 === 1 && number < 100;
});
// **********************************************************************
// 1: Sort an array from shortest string to the longest.
// **********************************************************************
const arrOfStrings = ['cat', 'wolf', 'yo', 'animal'];
const sortedByLength = [...arrOfStrings].sort((a, b) => {
return a.length - b.length
});
// ************************************************************************************
// https://www.codewars.com/kata/array-dot-diff/train/javascript
// Your goal in this kata is to implement a difference function, which subtracts one list from another and returns the result.
// It should remove all values from list a, which are present in list b.
// array_diff([1,2],[1]) == [2]
// If a value is present in b, all of its occurrences must be removed from the other:
// array_diff([1,2,2,2,3],[2]) == [1,3]
// ************************************************************************************
// ************************************************************************************
// https://www.codewars.com/kata/53da3dbb4a5168369a0000fe/train/javascript
// Create a function (or write a script in Shell) that takes an integer as an argument
// and returns "Even" for even numbers or "Odd" for odd numbers.
// ************************************************************************************
function even_or_odd(number) {
if (number % 2 === 0) {
return `Even`;
// ************************************************************************************
// https://www.codewars.com/kata/century-from-year/javascript
// 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.
// Task :
// Given a year, return the century it is in.
// Input , Output Examples ::
// centuryFromYear(1705) returns (18)
// centuryFromYear(1900) returns (19)
// ************************************************************
// 1: Reverse the array
// ************************************************************
const numbers = [3, 5, 6, 2];
const reversed = numbers.slice().reverse();
console.log(reversed); // => [ 2, 6, 5, 3 ]
console.log(numbers); // => [ 3, 5, 6, 2 ]