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
// 1: Calculate the total population in the given array (`data`): | |
const data = [ | |
{ | |
country: 'USA', | |
pop: 340 | |
}, | |
{ | |
country: 'France', | |
pop: 133 |
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
// ********************************************************************** | |
// 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 | |
}); |
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
// ************************************************************************************ | |
// 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] | |
// ************************************************************************************ | |
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
// ************************************************************************************ | |
// 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`; |
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
// ************************************************************************************ | |
// 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) |
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
// ************************************************************ | |
// 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 ] |