8kyu Codewars Flashcards

1
Q

Takes a string. Returns an array of strigns of each word followed by the length of that word

A
function addLength(str) {
  return str.split(' ').map((word) => (word += ` ${word.length}`));
}

addLength(‘hello world’) returns [‘hello 5’, ‘world 5’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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.

A
const areaOrPerimeter = function (l, w) {
  return l === w ? l * w : l * 2 + w * 2;
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Given the number (n), populate an array with all numbers up to and including that number, but excluding zero.

A

~~~
function monkeyCount(n) {
let arr = []
for (let i = 1; i <= n; i++) {
arr.push(i)
}
return arr
}
```

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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.

A

~~~
function printArray(array){
return array.toString()
}
```

How well did you know this?
1
Not at all
2
3
4
5
Perfectly