Some are very basic programming questions that are designed to show how a person thinks.
Givven an array of numbers, and a size parameter, the getNotOverlapping
is expected to return a
new array with equal or less item, which their values do not overlap in accordance to the size
variable.
function getNotOverlapping(arr, size){
}
console.log(
getNotOverlapping([0,1,2,3], 1), // 0,1,2,3
getNotOverlapping([0,1,2,3], 2) // 0,2
)
See Answer
[1, 2, 3, 4].reduce((acc, item, idx) =>
idx === 0 || acc[acc.length-1] + size <= item ?
[...acc, item]
: acc, [])
https://itnext.io/heres-why-mapping-a-constructed-array-doesn-t-work-in-javascript-f1195138615a
See Answer
[...new Array(5)].map((_, idx) => idx)
[1,2,null,undefined,3,,"3",,NaN,0,,,true,false, {}]
See Answer
.filter(Boolean)
See Answer
["Foo", "foO", "foo"].findIndex(item => item.toLowerCase() == 'foo')
See Answer
See Answer
Math.max(0, Math.min(100, num))
See Answer
https://stackoverflow.com/a/18234568/104380
'1234'.split('').reduce((result, digit, idx, arr) =>
(result + +digit)/(idx == arr.length-1 ? arr.length : 1)
, 0)
Or:
let num = '12345';
let sum = 0
for( let d of num )
sum += +d
console.log(sum/num.length) // 3
See Answer
![1,2,"3"].some(item => typeof item !== "number")
https://stackoverflow.com/a/52366332/104380
1011 + 11 // => 1110
https://stackoverflow.com/a/52372514/104380
function Example(name){
this.name = name;
window.addEventListener("click", this.clicked.bind(this))
}
Example.prototype.clicked = function(){
console.log(this.name)
}
Example.prototype.destroy = function(){
...
}
const example = new Example('foo')
var arr = [[1,2],[3,4],[5,6]]
console.log( [].concat(...arr) )
// ES2015 "flat":
arr.flat();
1201977 => [[1,2], [2,1], [0,1], [9,1], [7,2]]
[1, 10, 11, 1010, 1981] => [false, false, true, true, true]
[1,2] + [3,4]
https://stackoverflow.com/questions/8935632/check-if-character-is-number/32572539#32572539
var foo = (...a) => console.log(a);
foo([1,2,3], 4)
var foo = (...[a]) => console.log(a);
foo([1,2,3], 4)
https://stackoverflow.com/a/57491707/104380
See Answer
[{a:1}, {b:2}, {c:3}].reduce((newArr, item, idx) => {
if( idx != 1 )
newArr.push({...item})
return newArr
}, [])