8kyu Codewars Flashcards
Takes a string. Returns an array of strigns of each word followed by the length of that word
function addLength(str) { return str.split(' ').map((word) => (word += ` ${word.length}`)); }
addLength(‘hello world’) returns [‘hello 5’, ‘world 5’]
You are given the length and width of a 4-sided polygon. The polygon can either be a rectangle or a square. If it is a square, return its area. If it is a rectangle, return its perimeter.
const areaOrPerimeter = function (l, w) { return l === w ? l * w : l * 2 + w * 2; };
Given the number (n), populate an array with all numbers up to and including that number, but excluding zero.
~~~
function monkeyCount(n) {
let arr = []
for (let i = 1; i <= n; i++) {
arr.push(i)
}
return arr
}
```
Given an array of elements e.g. [“h”,”o”,”l”,”a”], return a string with comma delimited elements of the array in th same order.
~~~
function printArray(array){
return array.toString()
}
```