Mode entretien. Minuteur de 7 min, sans indices ni autocomplétion
Pairs by character
FacileMap and Set7 min
You get two arrays of objects like { c, a }. The field c is one character, the field a is an integer. Within one array a character occurs at most once.
Write a function sumOfProducts(first, second). For every character that is in both arrays, multiply their a numbers. Return the sum of these products.
Exemples
sumOfProducts([{ c: 'a', a: 5 }, { c: 'b', a: 6 }], [{ c: 'b', a: 4 }, { c: 'a', a: 2 }])Renvoie 34
sumOfProducts([{ c: 'x', a: 3 }], [{ c: 'y', a: 7 }])Renvoie 0
Posé chez Google · Source
Chargement de l'éditeur...
- Entrée
sumOfProducts([ { c: 'a', a: 5 }, { c: 'b', a: 6 } ], [ { c: 'b', a: 4 }, { c: 'a', a: 2 } ])Attendu34 - Entrée
sumOfProducts([ { c: 'x', a: 3 } ], [ { c: 'y', a: 7 } ])Attendu0 - Entrée
sumOfProducts([ { c: 'a', a: 1 }, { c: 'b', a: 2 }, { c: 'c', a: 3 } ], [ { c: 'c', a: 10 }, { c: 'd', a: 4 } ])Attendu30
Les tests cachés se lancent à la soumission